-1

I have date Ranges for A and B like below d1,d2...d3 are actual Date I need to get date Ranges that are Covered by A but not by B in Output. I am thinking of creating a function that collects date range arrays for A and B and then take A and compare against each ranges for B and evaluate the diff. my question is that, is there a better way to do this and is there a function that returns Date range Difference given pair of date Ranges.

|d1-------------d6|    |d9----------d14|    |d16----------------d21|  **Line For A
    |d5--------------d10|   |d12----d14|       |d17-----------d20|   |d25-------d30| **Line For B

Output:
d1  d5
d10 d12
d16 d17
d20 d21
Justin Homes
  • 3,739
  • 9
  • 49
  • 78

2 Answers2

0

Use DateTime in c#. I don't know if there is a equivalence in Java

john
  • 1
0

I think TimeSpan is what you want:

DateTime d1 = DateTime.Now;
DateTime d2 = DateTime.Now.AddDays(-1);

TimeSpan t = d1 - d2;
int mins = t.TotalMinutes;  //what ever you want, Years, Months, Days, Hrs, Mins, Seconds

In Java the equivilent is How can I calculate a time span in Java and format the output?

Community
  • 1
  • 1
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • no because if i have drangeA=1/1/2012 to 7/5/2012 drangeB=3/1/2012 to 3/15/2012 output should be Dates range Not cover B but by A 1/1/2012 to 3/1/2012 and 3/15/2012 to 7/5/2012 – Justin Homes Mar 16 '13 at 00:51