CSharp examples for System:DateTime Week
Get all weekdays between a period
using System.Text; using System.Linq; using System.Collections.Generic; using System;//from w w w .j a v a 2 s . c o m public class Main{ /// <summary> /// Get all weekdays between a period /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <returns></returns> public static List<DateTime> GetWeekdaysDate(DateTime startDate, DateTime endDate) { DateTime tempDate = startDate; List<DateTime> result = new List<DateTime>(); while (tempDate <= endDate) { if (tempDate.DayOfWeek != DayOfWeek.Saturday && tempDate.DayOfWeek != DayOfWeek.Sunday) { result.Add(tempDate); } tempDate = tempDate.AddDays(1); } return result; } }