c# - How to get list of monthly periods? -
i have starting date , number of months. need create specific number of monthly periods example:
var startingdate = new datetime(2010,1,15); var months = 3; (int = 0; < months; i++) { console.writeline("{0} {1} {2}", + 1, startingdate.addmonths(i), startingdate.addmonths(i + 1).adddays(-1)); } output: 1 2010-1-15 2010-2-14 2 2010-2-15 2010-3-14 3 2010-3-15 2010-4-14 in case code simple , works. when startdate datetime(2010,1,31) result is:
output: 1 2010-1-31 2010-2-27 2 2010-2-28 2010-3-30 3 2010-3-31 2010-4-29 are these periods correct?
the periods funky correct.
if periods starting on last day of month end on second last day of next month.
Comments
Post a Comment