Re: Date Difference - Qsn
- From: Eric Sosman <esosman@xxxxxxxxxxxxxxxxxxx>
- Date: Mon, 28 May 2007 21:22:25 -0400
Hal Rosser wrote:
"alij" <aliasger.jaffer@xxxxxxxxx> wrote in message news:1180383514.291807.156870@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxHi,Use your Yankee engineering and the getTime() method of the Date class
I have two dates and I want to find the difference in years between
them. I noticed the Date class doesn't provide me with such a function
like datediff. Will appreciate any pointers how I can go about this.
if you know how many milliseconds there are between two dates, you can cipher it out...
Assuming the two dates are date1 and date2 you can try this...
long dateDiffms = date1.getTime() - date2.getTime()
double yrsDiff = dateDiffms / (1000 * 60 * 60 * 24 * 365); // assuming its not a leap year
Be careful! `1000 * 60 * 60 * 24 * 365' is 1471228928
milliseconds, which is a little over seventeen days. How
the years fly by as I grow older!
(ObJavaQuestion: Explain why the "obviously correct"
calculation turns out so badly wrong, and suggest a fix.)
--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxx
.
- Follow-Ups:
- Re: Date Difference - Qsn
- From: Hal Rosser
- Re: Date Difference - Qsn
- References:
- Date Difference - Qsn
- From: alij
- Re: Date Difference - Qsn
- From: Hal Rosser
- Date Difference - Qsn
- Prev by Date: Re: Date Difference - Qsn
- Next by Date: Re: Newb taglib conceptual error: Missing tagclass for tag "dbgrid"
- Previous by thread: Re: Date Difference - Qsn
- Next by thread: Re: Date Difference - Qsn
- Index(es):
Relevant Pages
|