• Post Reply Bookmark Topic Watch Topic
  • New Topic

date overlapping  RSS feed

 
Nimish Patel
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Have a good day............
now i have four dates in long format ( converted by UTC date method)
in long format, we can comparision using "<",">" operator.

now i want to find ovarlapping.
how many condition i have to checked.

suppose in databse, fromdate value - 10-jul-2005. todate value- 12-jul-2005

now user enter fromdate value from UI,like 11-jul-2005.
and totime value from UI ,like 13-jul-2005, so this time overlapping occurs.

when user enter from date value 8-jul-2005, todate value 9-jul-2005,
so this time no overlapping.

i have all four dates in long format.

long fromDB, long toDB , long fromUI , long toUI
SO we can apply "<",">".

but i cannot check all condition.

please give some advise.

thanks,
Nimish Patel
 
Ryan McGuire
Ranch Hand
Posts: 1143
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nimish Patel:
hi,

Have a good day............
now i have four dates in long format ( converted by UTC date method)
in long format, we can comparision using "<",">" operator.

now i want to find ovarlapping.
how many condition i have to checked.

suppose in databse, fromdate value - 10-jul-2005. todate value- 12-jul-2005

now user enter fromdate value from UI,like 11-jul-2005.
and totime value from UI ,like 13-jul-2005, so this time overlapping occurs.

when user enter from date value 8-jul-2005, todate value 9-jul-2005,
so this time no overlapping.

i have all four dates in long format.

long fromDB, long toDB , long fromUI , long toUI
SO we can apply "<",">".

but i cannot check all condition.

please give some advise.

thanks,
Nimish Patel


Given four things, there are usually 4! or 24 ways to order them. However, if we assume that fromDB<toDB and fromUI<toUI, then there are only 6:

fromDB < toDB < fromUI < toUI -- no overlap
fromDB < fromUI < toDB < toUI -- overlap
fromDB < fromUI < toUI < toDB -- overlap
fromUI < toUI < fromDB < toDB -- no overlap
fromUI < fromDB < toUI < toDB -- overlap
fromUI < fromDB < toDB < toUI -- overlap

What is the simplest if/then/else structure or boolean expression you can come up with to determine which of these lines fits a given set values?

The next trick is to make sure this works for cases where fromUI=toDB or fromDB=toUI. Also, is the assumption that fromDB<toDB and fromUI<toUI valid?
 
Nimish Patel
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Ryan

Thanks a lot.

regards,
Nimish Patel
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scroll down the forum for another post on date ranges. I suspect it's someone you know doing the same homework. See if those ideas help, too.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!