Number of days difference

C

CheGueVerra

Hi All trying to figure out how to calculate the difference in days between
two dates

TIA

CheGueVerra
 
D

Dotty

CheGueVerra said:
Hi All trying to figure out how to calculate the difference in days between
two dates

TIA

CheGueVerra

You could convert each date to Julian and subtract.
If you want just date difference and not time within the day
you could delete the fractional part of the Julian dates.
 
A

Alan Krueger

CheGueVerra said:
Hi All trying to figure out how to calculate the difference in days between
two dates

Each Date tracks time in milliseconds since an epoch date. Take the
difference between these two values and convert from milliseconds to days.
 
E

Eric Sosman

Alan said:
Each Date tracks time in milliseconds since an epoch date. Take the
difference between these two values and convert from milliseconds to days.

It depends on what he means by "difference in days."
For example, should the span from 31-Dec-2004 23:59:59
and 01-Jan-2005 00:00:01 be "an insignificant fraction
of a day, rounded down to zero" or "one day?"
 
T

Tilman Bohn

In message <[email protected]>,
Eric Sosman wrote on Fri, 25 Feb 2005 12:00:33 -0500:

[...]
It depends on what he means by "difference in days."
For example, should the span from 31-Dec-2004 23:59:59
and 01-Jan-2005 00:00:01 be "an insignificant fraction
of a day, rounded down to zero" or "one day?"

That's not the end of it. Let's assume for a moment he'd consider it
one day. Now what do you do with the difference between 31-Dec-1998
06:00:00 and 01-Jan-1999 06:00:00? Consider: It's the interval between
two identical times on two consecutive days. And yet it is one second
more than 24 hours due to a leap second. One day or two?
 
J

Jacob

CheGueVerra said:
Hi All trying to figure out how to calculate the difference in days between
two dates

The Day class was written to overcome the problems
of java.util.Date and java.util.Calendar which mix
dates and times in a confusing manner:

http://geosoft.no/software/day/Day.java.html

Day day1 = new Day (year1, month1, day1);
Day day2 = new Day (year2, month2, day2);
int daysBetween = day1.daysBetween (day2);
 
T

Tilman Bohn

In message <[email protected]>,
Jacob wrote on Fri, 25 Feb 2005 21:04:52 +0100:

[...]
int daysBetween = day1.daysBetween (day2);

The fact remains that the problem as originally stated is under-
determined. Which implies that I think the Javadoc of Paul Hill's Day
class (specifically, of daysBetween()) is incomplete as it doesn't state
its definition of `days between', either.
 
J

Jacob

Tilman said:
The fact remains that the problem as originally stated is under-
determined. Which implies that I think the Javadoc of Paul Hill's Day
class (specifically, of daysBetween()) is incomplete as it doesn't state
its definition of `days between', either.

java.util.Date is a class for modelling an instant in time.
Your previous example and concern is valid for this data type
as you need to introduce rounding rules for determining number
of days between two dates.

The Day class is different in that there is no time component,
time zone, daylight saving time or leap seconds. It is class
for modelling the running entries of a desktop calendar.
The difference between two days becomes well defined; the axiom
beeing that the difference between two instances of the same
day is 0.

If your concern is how many (whole) days there might be between
two carefully choosen instances in _time_, this is not the
class for you. For finance applications where time is a discrete
property of days, using the java.util.Date API is clearly a risk,
and the Day class is probably better suited.
 
T

Tilman Bohn

In message <[email protected]>,
Jacob wrote on Sat, 26 Feb 2005 10:30:31 +0100:

[...]
The Day class is different in that there is no time component,
time zone, daylight saving time or leap seconds. It is class
for modelling the running entries of a desktop calendar.
The difference between two days becomes well defined;
[...]

Yes, I understand. I didn't claim it was ill-defined, only that the
Javadoc was lacking in that it doesn't clearly lay this out. I didn't
mean to imply any criticism of the design itself, and the Javadoc is
certainly not incorrect. I just find it a bit terse. (Maybe it's just
me, but I did have to look at the code to know what exactly to expect
from daysBetween().)
 
T

Thomas G. Marshall

Jacob coughed up:
The Day class was written to overcome the problems
of java.util.Date and java.util.Calendar which mix
dates and times in a confusing manner:

http://geosoft.no/software/day/Day.java.html

Day day1 = new Day (year1, month1, day1);
Day day2 = new Day (year2, month2, day2);
int daysBetween = day1.daysBetween (day2);


Yes. To the OP. Your question is *truly* a can of worms open at both ends.
The answer to your question requires many more things to be stipulated.

Years ago I did several searches on google to try to solve a very similar
problem. I basically got dizzy from the implications of the things I didn't
specify in my problem.


--
Iamamanofconstantsorrow,I'veseentroubleallmydays.Ibidfarewelltoold
Kentucky,TheplacewhereIwasbornandraised.ForsixlongyearsI'vebeenin
trouble,NopleasureshereonearthIfound.ForinthisworldI'mboundtoramble,
Ihavenofriendstohelpmenow....MaybeyourfriendsthinkI'mjustastrangerMyface,
you'llneverseenomore.ButthereisonepromisethatisgivenI'llmeetyouonGod's
goldenshore.
 
C

CheGueVerra

Yes. To the OP. Your question is *truly* a can of worms open at both
ends. The answer to your question requires many more things to be
stipulated.

Years ago I did several searches on google to try to solve a very similar
problem. I basically got dizzy from the implications of the things I
didn't specify in my problem.

Yup, I just got a glimpse of it myself when I googled it today... I see that
the trouble of even the question can be picky. I have talked to the main
guy over here and basically a day is a day is a day, meaning that we really
don't take into consideration anything lower than the day field, that should
help out a bit. Oh, yeah I see some thinking about posting about the
daylight savings some day have 23 some have 25... I shal repeat the the day
field is the smallest fiels we consider for the time being.

So how can I resolve the big Mystery of nbDays = endDate- startDate ????

PS, I couldn't find Day object.. so I guess it's not from sun ??? where can
I get docs on this , yup I'm nuub

CheGueVerra
 
T

Thomas G. Marshall

CheGueVerra coughed up:
Thanks for the link to your work, was very nice of you...


Report back any issues you discover along the way. This topic is a
mine-field for almost anyone.


CheGueVerra

And send us some cigars.
 
C

CheGueVerra

Report back any issues you discover along the way. This topic is a
mine-field for almost anyone.

Well, nuub as I am, I haven't even been able to include the jar file in my
projet ...
I put the jar file in the directory that other jar files are, but when i try
to import the pacage

import no.geosoft.cc.util.*;

I get an error, package not found ..
I'll try to see what I'm doing wrong, but really not sure ...


CheGueVerra
 
C

CheGueVerra

Ok,

Fixed the import thing, was just some compiler settings I didn't know about
learning, learning, learning.

Now for the "NUMBER of DAYS difference" gather around gather around

I created a sample project to view the calss in action

java.util.Date startDate = df.parse(startDateStr); [df = SimpleDateFormat]
java.util.Date endDate = df.parse(endDateStr);

Day firstDay = new Day(startDate.getYear() + 1900, startDate.getMonth(),
startDate.getDate());
Day lastDay = new Day(endDate.getYear() + 1900, endDate.getMonth(),
endDate.getDate());
int nbDays = firstDay.daysBetween(lastDay); [The order of compare is not
important lastDay.daysBetween(firstDay) will give same answer]

So I hope this helps futur generations of java programmers
the day.jar can be found here
http://geosoft.no/software/day/Day.java.html


CheGueVerra
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top