compare two dates MMDDYYYY

Discussion in 'Perl Misc' started by yeti349@yahoo.com, Jul 22, 2005.

  1. Guest

    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?
     
    , Jul 22, 2005
    #1
    1. Advertising

  2. 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
     
    Eric Schwartz, Jul 22, 2005
    #2
    1. Advertising

  3. 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/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.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jul 22, 2005
    #3
  4. Bart Lateur Guest

    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.
     
    Bart Lateur, Jul 23, 2005
    #4
  5. Guest

    Bart Lateur wrote:
    > 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.
     
    , Jul 23, 2005
    #5
  6. Guest

    I apologize for the newbie-ish post. I was in a rush and just typed out
    my questions...
     
    , Jul 23, 2005
    #6
  7. wrote:
    > Gunnar Hjalmarsson wrote:
    >> 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
     
    Gunnar Hjalmarsson, Jul 23, 2005
    #7
  8. Guest

    Great done, Gunnar. You're parents have raised you well.
     
    , Jul 23, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    911
    Rob Schieber
    Sep 30, 2005
  2. GenxLogic
    Replies:
    3
    Views:
    1,379
    andrewmcdonagh
    Dec 6, 2006
  3. Tony Girgenti

    How do I compare dates from two calendar controls on web form ?

    Tony Girgenti, Sep 27, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    178
    Tony Girgenti
    Sep 27, 2006
  4. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    235
    Mark Schupp
    Aug 9, 2004
  5. PerlFAQ Server
    Replies:
    0
    Views:
    198
    PerlFAQ Server
    Feb 6, 2011
Loading...

Share This Page