![]() |
compare two dates MMDDYYYY
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? |
Re: compare two dates MMDDYYYY
yeti349@yahoo.com 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 |
Re: compare two dates MMDDYYYY
yeti349@yahoo.com 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 |
Re: compare two dates MMDDYYYY
yeti349@yahoo.com 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. |
Re: compare two dates MMDDYYYY
Bart Lateur wrote: > yeti349@yahoo.com 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. |
Re: compare two dates MMDDYYYY
I apologize for the newbie-ish post. I was in a rush and just typed out
my questions... |
Re: compare two dates MMDDYYYY
yeti349@yahoo.com wrote:
> Gunnar Hjalmarsson wrote: >> yeti349@yahoo.com 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 |
Re: compare two dates MMDDYYYY
Great done, Gunnar. You're parents have raised you well.
|
| All times are GMT. The time now is 07:13 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.