• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

What class to use for date-related calculations.

 
Ranch Hand
Posts: 531
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to disregard records more than 48 hours removed. So what would you advise I use: Date or Calendar?
 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Date is lighter & faster (by a huge amount) and simpler for Mr JP and there is no need for Calendar.

You can get a Date from the database format using SimpleDateFormat, then you can subtract 48hrs from it and compare it with the current date.
 
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mike acre:
Date is lighter & faster (by a huge amount) and simpler for Mr JP and there is no need for Calendar.

You can get a Date from the database format using SimpleDateFormat, then you can subtract 48hrs from it and compare it with the current date.



Beware of the use of Date and attempts to determine today's date from it. The value is stored in UTC (GMT) and as such if you aren't in England or its summer, your value for midnight isn't the same as Date's. The easiest way around this is to use the SimpleDateFormat to convert midnight this morning to a Date and then use that in calculations.
 
Anton Golovin
Ranch Hand
Posts: 531
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the method... I bet there is an easier way...


[ September 07, 2004: Message edited by: Anton Golovin ]
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anton Golovin:
Here's the method... I bet there is an easier way...


Here's what I do, I only allow today, tomorrow and the day after.

It calsulates minDate as midnight this morning, then calculates the max date as 2 days later. Since all values are at midnight, time == 0, this will work. Here's the Functions methods:
 
It wasn't my idea to go to some crazy nightclub in the middle of nowhere. I just wanted to stay home and cuddle with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic