WebOct 7, 2024 · List datelist=new List(); while (dt1 <= dt2) { datelist.Add(dt1); dt1 = dt1.AddDays(1); } DateTime[] dates = datelist.ToArray(); Marked as answer byAnonymousThursday, October 7, 2024 … WebJun 17, 2024 · 1) Change the method to return an array of DateTime values: C# public DateTime [] GetDatesBetween (DateTime startDate, DateTime endDate) { List allDates = new List (); for (DateTime date = startDate; date <= endDate; date = date.AddDays ( 1 )) allDates.Add (date); return allDates.ToArray (); }
c# - How to loop between two dates - Stack Overflow
WebNov 30, 2009 · public static List Weekdays (DateTime startDate, DateTime endDate) { if (startDate > endDate) { Swap (ref startDate, ref endDate); } List days = new List (); var ts = endDate - startDate; for (int i = 0; i < ts.TotalDays; i++) { var cur = startDate.AddDays (i); if (cur.DayOfWeek != DayOfWeek.Saturday && cur.DayOfWeek != DayOfWeek.Sunday) … WebAug 28, 2015 · I have a C# method like this: public static int DaysLeft (DateTime startDate, DateTime endDate, Boolean excludeWeekends, String excludeDates) { } What it's supposed to do is calculate the number of days between the startDate and endDate, but optionally needs to exclude weekends and also other dates (passed in as a comma-separated … centar izvrsnosti sdž
c# - LINQ expression to generate a list of days between two dates ...
WebJun 16, 2024 · 1) Change the method to return an array of DateTime values: C# public DateTime [] GetDatesBetween (DateTime startDate, DateTime endDate) { … WebApr 9, 2015 · I'm given two dates, a start date and an end date and on a specified interval I need to take some action. For example: for every date between 3/10/2009 on every third day until 3/26/2009 I need to create an entry in a List. So my inputs would be: DateTime StartDate = "3/10/2009"; DateTime EndDate = "3/26/2009"; int DayInterval = 3; WebDec 12, 2012 · Of course you can, there is no "between" syntax if that's what you are getting at but it's relatively simple to do e.g. list.Where(x => x.Date >= StartDate && x.Date <= EndDate); If you want better readability, you … centar cvjetni trgovine