What I would like to do is as follows
Given two dates e.g. March 02, 1998 and September 25, 2011. How to get split the interval into
- March 02, 1998 to March 31, 1998 ( 30 Days)
- April 01, 1998 to December 31, 1998 ( 9 Months)
- January 01, 1999 to December 31, 2010 ( 11 Years)
- January 01, 2011 to August31, 2011 ( 8 Months)
-
September 01, 2011 to September 25, 2011 ( 30 Days)
However if any of the interval doesn’t exist, we don’t wan to force include it i.e. the result will not always be days/months/years/months/days e.g.
Given start date = ‘1998-02-01’ and end date = ‘2011-03-31’,
The expect results is (Months/Years/Months)1998-02-01 ==> 1998-12-31
1999-01-01 ==> 2010-12-31
2011-01-01 ==> 2011-03-31Given start date = ‘1998-02-01’ and end date = ‘1998-03-31’,
The expect results is (2 Months)1998-02-01 ==> 2011-03-31
Given start date = ‘1998-01-05’ and end date = ‘1998-02-03’,
The expect results is (Days/Days)
1998-01-05 ==> 2011-01-31
1998-02-01 ==> 2011-02-03
Have a look at the following in case my description does not make sense. I am trying to accomplish the same but in .net
Algorithm to find optimal day/month/year intervals to in an arbitrary timeframe?
You can just do like this:
Output: