Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   compare two dates MMDDYYYY (http://www.velocityreviews.com/forums/t893402-compare-two-dates-mmddyyyy.html)

yeti349@yahoo.com 07-22-2005 07:17 PM

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?


Eric Schwartz 07-22-2005 07:43 PM

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

Gunnar Hjalmarsson 07-22-2005 09:00 PM

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

Bart Lateur 07-22-2005 11:32 PM

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.

yeti349@yahoo.com 07-23-2005 12:16 AM

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.


yeti349@yahoo.com 07-23-2005 12:18 AM

Re: compare two dates MMDDYYYY
 
I apologize for the newbie-ish post. I was in a rush and just typed out
my questions...


Gunnar Hjalmarsson 07-23-2005 12:54 AM

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

yeti349@yahoo.com 07-23-2005 02:28 AM

Re: compare two dates MMDDYYYY
 
Great done, Gunnar. You're parents have raised you well.



All times are GMT. The time now is 01:25 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.