compare two dates MMDDYYYY

Y

yeti349

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?
 
E

Eric Schwartz

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
 
G

Gunnar Hjalmarsson

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/clpmisc/clpmisc_guidelines.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.
 
B

Bart Lateur

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...
 
Y

yeti349

Bart said:
$_ = '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...


Wow, thank you Bart.
 
Y

yeti349

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

Gunnar Hjalmarsson

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.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top