For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > September 2004 > Number of Days Between 2 Dates.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Number of Days Between 2 Dates.
Fred Goldberg

2004-09-28, 9:27 pm

I have the current releace of ActiveState for Win32.

I'm by the shear number of time and date modules and exactly what
they are capable of doing. I need help calculating the number of days
(including wends) between two dates. All dates are in the format of
mm/dd/yyyy. This format can be changed if needed.

What module is best to use and what is the format of the function. Thanks.

Fred

Brendon Caligari

2004-09-28, 9:27 pm

Fred Goldberg wrote:

> I have the current releace of ActiveState for Win32.
>
> I'm by the shear number of time and date modules and exactly what
> they are capable of doing. I need help calculating the number of days
> (including wends) between two dates. All dates are in the format of
> mm/dd/yyyy. This format can be changed if needed.
>
> What module is best to use and what is the format of the function. Thanks.


Time::Local should do the trick

The docs are pretty straight forward. timelocal is most likely the
function you're after.

B.


Gunnar Hjalmarsson

2004-09-28, 9:27 pm

Fred Goldberg wrote:
> I'm by the shear number of time and date modules and
> exactly what they are capable of doing. I need help calculating the
> number of days (including wends) between two dates. All dates
> are in the format of mm/dd/yyyy. This format can be changed if
> needed.
>
> What module is best to use


Probably Date::Calc.

> and what is the format of the function.


See the docs for the module. Reading the docs doesn't confuse you,
does it?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Gunnar Hjalmarsson

2004-09-28, 9:27 pm

Brendon Caligari wrote:
> Fred Goldberg wrote:
>
> Time::Local should do the trick


Well, I agree, even if I suggested Date::Calc in another message.
Reminds me of another thread in this group:
http://groups.google.com/groups?sel...40uni-berlin.de

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Abigail

2004-09-28, 9:27 pm

Brendon Caligari (bcaligari@nospam.fireforged.com) wrote on MMMMXLVI
September MCMXCIII in <URL:news:4159d38b$0$94918$bed64819@news.gradwell.net>:
__ Fred Goldberg wrote:
__
__ > I have the current releace of ActiveState for Win32.
__ >
__ > I'm by the shear number of time and date modules and exactly what
__ > they are capable of doing. I need help calculating the number of days
__ > (including wends) between two dates. All dates are in the format of
__ > mm/dd/yyyy. This format can be changed if needed.
__ >
__ > What module is best to use and what is the format of the function. Thanks.
__
__ Time::Local should do the trick


Well, it can do the trick, and so can Math::BigInt.

__ The docs are pretty straight forward. timelocal is most likely the
__ function you're after.

Really? If I look at the pretty straight forward docs, the docs tell me
that timelocal takes a date/time value which is broken down in seconds,
minutes, hours, day of month, month and year (with the month counted
as January 0, February 1, etc, and some complicated rules on what the
year should be), and returns an integer giving us seconds
since January 1, 1970 GMT. (It falsely says midnight, but it's actually
about half a minute past midnight, due to leap seconds).

It takes some extra work to use this to calculate the difference between
two dates correctly. The docs also say it may not work for dates before
Jan 1, 1970. Nor will it, according to the docs, work on most systems
for dates before Dec 1901, or after Jan 2038.

I'd say that while it's not impossible to use Time::Local, it's awkward,
and will only work for a limited set of dates.

Date::Calc on the other hand has a function, Delta_Days() that does
exactly what the OP wants.


Abigail
--
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
Jim Keenan

2004-09-28, 9:27 pm

Fred Goldberg wrote:

> I have the current releace of ActiveState for Win32.
>
> I'm by the shear number of time and date modules and exactly what
> they are capable of doing. I need help calculating the number of days
> (including wends) between two dates. All dates are in the format of
> mm/dd/yyyy. This format can be changed if needed.
>
> What module is best to use and what is the format of the function. Thanks.
>
> Fred
>

As other posters have stated, try Date::Calc. I use it in production
code at work. IIRC, ActiveState has a ppm for Date::Calc which means
that you don't need to have an installed C-compiler to install it. And
DeltaDays is indeed the function you want to use.

jimk
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com