How to group a period of time into yearly periods ? (split timespan into yearly periods)
Posted
by
user315648
on Stack Overflow
See other posts from Stack Overflow
or by user315648
Published on 2012-03-28T17:11:24Z
Indexed on
2012/03/28
17:30 UTC
Read the original article
Hit count: 163
I have a range of two datetimes:
DateTime start = new DateTime(2012,4,1);
DateTime end = new DateTime(2016,7,1);
And I wish to get all periods GROUPED BY YEAR between this period. Meaning the output has to be:
2012-04-01 - 2012-12-31
2013-01-01 - 2013-12-31
2014-01-01 - 2014-12-31
2015-01-01 - 2015-12-31
2016-01-01 - 2016-07-01
Preferably the output would be in IList<Tuple<DateTime,DateTime>>
list.
How would you do this ? Is there anyway to do this with LINQ somehow ?
Oh and daylight saving time is not absolutely critical, but surely a bonus.
Thanks!
© Stack Overflow or respective owner