I am trying to make a function which gives all month name between two dates in c#
List<string> liMonths = MyFunction(date1,date2);
my function is
MyFunction(DateTime date1,DateTime date2)
{
//some code
return listOfMonths;
}
can you help me how could i do this
MONTHS_BETWEEN returns number of months between dates date1 and date2 . If date1 is later than date2 , then the result is positive. If date1 is earlier than date2 , then the result is negative. If date1 and date2 are either the same days of the month or both last days of months, then the result is always an integer.
date(2020, 1, 1) today = datetime. date. today() for month in months_between(start_of_2020, today): print(month. strftime("%B %Y")) # January 2020, February 2020, March 2020, …
No linq-solution yet?
var start = new DateTime(2013, 1, 1);
var end = new DateTime(2013, 6, 22);
// set end-date to end of month
end = new DateTime(end.Year, end.Month, DateTime.DaysInMonth(end.Year, end.Month));
var diff = Enumerable.Range(0, Int32.MaxValue)
.Select(e => start.AddMonths(e))
.TakeWhile(e => e <= end)
.Select(e => e.ToString("MMMM"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With