Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > compare two dates MMDDYYYY

Reply
Thread Tools

compare two dates MMDDYYYY

 
 
yeti349@yahoo.com
Guest
Posts: n/a
 
      07-22-2005
Hi,

how can I use Time::Local to convert MMDDYYYY dates to secs and compare
the two to find difference in days? I've looked over the faqs and
documentation, but have had no success...thanks

can I use timegm() or localtime() with my current date format, or do I
need to modify it?

 
Reply With Quote
 
 
 
 
Eric Schwartz
Guest
Posts: n/a
 
      07-22-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:
> how can I use Time::Local to convert MMDDYYYY dates to secs and compare
> the two to find difference in days? I've looked over the faqs and
> documentation, but have had no success...thanks


I'd use Date::Calc or Date::Manip, depending on your circumstances.
Date::Calc is a great deal faster, but has a C extension; Date::Manip
is pure Perl, but slower (it also has a number of extra functions, but
I doubt you'll need them).

> can I use timegm() or localtime() with my current date format, or do I
> need to modify it?


Both timegm() and timelocal() (I assume you meant timelocal() instead
of localtime() ?) take a list, so in both cases, you'll need to
separate out the components of your date string into month, day, and
year components to pass into those functions. But why do all that
hard work, when Date::Calc can do it for you for free?

-=Eric
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      07-22-2005
(E-Mail Removed) wrote:
> how can I use Time::Local to convert MMDDYYYY dates to secs and compare
> the two to find difference in days? I've looked over the faqs and
> documentation, but have had no success...


In what respect have you had no success?

Please study the posting guidelines for this group:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

Then, unless you decide to go for Eric's suggestion instead, let's see
what you have, and somebody may be able to get it right.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Bart Lateur
Guest
Posts: n/a
 
      07-22-2005
(E-Mail Removed) wrote:

>how can I use Time::Local to convert MMDDYYYY dates to secs and compare
>the two to find difference in days? I've looked over the faqs and
>documentation, but have had no success...thanks


$_ = '23072005';
my($d, $m, $y) = /(\d{2})(\d{2})(\d{4})/;
$m--; # months are 0-based
use Time::Local;
my $time = timegm(0, 0, 0, $d, $m, $y); #GMT is DST-independent
print scalar localtime($time);

I think you can take it from here...

--
Bart.
 
Reply With Quote
 
yeti349@yahoo.com
Guest
Posts: n/a
 
      07-23-2005


Bart Lateur wrote:
> (E-Mail Removed) wrote:
>
> >how can I use Time::Local to convert MMDDYYYY dates to secs and compare
> >the two to find difference in days? I've looked over the faqs and
> >documentation, but have had no success...thanks

>
> $_ = '23072005';
> my($d, $m, $y) = /(\d{2})(\d{2})(\d{4})/;
> $m--; # months are 0-based
> use Time::Local;
> my $time = timegm(0, 0, 0, $d, $m, $y); #GMT is DST-independent
> print scalar localtime($time);
>
> I think you can take it from here...
>
> --
> Bart.



Wow, thank you Bart.

 
Reply With Quote
 
yeti349@yahoo.com
Guest
Posts: n/a
 
      07-23-2005
I apologize for the newbie-ish post. I was in a rush and just typed out
my questions...

 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      07-23-2005
(E-Mail Removed) wrote:
> Gunnar Hjalmarsson wrote:
>> (E-Mail Removed) wrote:
>>> how can I use Time::Local to convert MMDDYYYY dates to secs and compare
>>> the two to find difference in days? I've looked over the faqs and
>>> documentation, but have had no success...

>>
>> In what respect have you had no success?

>
> I apologize for the newbie-ish post. I was in a rush and just typed out
> my questions...


That's not what you said. You said that you've "looked over the faqs and
documentation".

There is no reason to apologize for being a newbie. Telling lies is
quite another story.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
yeti349@yahoo.com
Guest
Posts: n/a
 
      07-23-2005
Great done, Gunnar. You're parents have raised you well.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 4.14 How can I compare two dates and find the difference? PerlFAQ Server Perl Misc 0 02-06-2011 11:00 AM
How to compare two SOAP Envelope or two Document or two XML files GenxLogic Java 3 12-06-2006 08:41 PM
How do I compare dates from two calendar controls on web form ? Tony Girgenti ASP .Net Web Controls 0 09-27-2006 05:16 PM
Dates dates dates dates... SQL and ASP.NET David Lozzi ASP .Net 1 09-30-2005 02:18 PM
Dates! Dates! Dates! PW ASP General 4 08-09-2004 04:42 PM



Advertisments