Compare Dates

Discussion in 'Perl Misc' started by amerar@iwc.net, Aug 31, 2007.

  1. Guest

    Hi All,

    Here is a good one: I need to compare 2 dates, without the year.
    Basically I want to know if a specific calendar date falls between two
    other dates. Everything is in YYYY-MO-DD, the way Perl wants it.

    So, say I am looking for a birthday. I do not care about the year, I
    just want to know if a birthday falls between two dates in the
    calendar.......

    Any suggestions? Date::Manip??? Did not seem to do what I want.

    Thanks!
     
    , Aug 31, 2007
    #1
    1. Advertising

  2. wrote:
    > Here is a good one: I need to compare 2 dates, without the year.
    > Basically I want to know if a specific calendar date falls between two
    > other dates. Everything is in YYYY-MO-DD, the way Perl wants it.


    Just strip the year:

    my $day = substr $date, 5;

    and do stringwise comparisons.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Aug 31, 2007
    #2
    1. Advertising

  3. Ben Bullock Guest

    On Fri, 31 Aug 2007 09:24:36 -0700, wrote:

    > Here is a good one: I need to compare 2 dates, without the year.
    > Basically I want to know if a specific calendar date falls between two
    > other dates. Everything is in YYYY-MO-DD, the way Perl wants it.
    >
    > So, say I am looking for a birthday. I do not care about the year, I
    > just want to know if a birthday falls between two dates in the
    > calendar.......
    >
    > Any suggestions? Date::Manip??? Did not seem to do what I want.


    Change the year of all your dates to be the same arbitrary year (make it a
    leap year), then use the Day_of_Year function from
    Date::Calc to get the day of the year (see
    http://www.unix.org.ua/orelly/perl/cookbook/ch03_07.htm), then compare the
    numbers.
     
    Ben Bullock, Sep 1, 2007
    #3
    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:
    893
    Rob Schieber
    Sep 30, 2005
  2. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    222
    Mark Schupp
    Aug 9, 2004
  3. Replies:
    1
    Views:
    228
    Jano Svitok
    Jul 17, 2007
  4. kellygreer1

    RFC-822 dates into Ruby dates

    kellygreer1, Jun 8, 2008, in forum: Ruby
    Replies:
    1
    Views:
    230
    Eric I.
    Jun 8, 2008
  5. Dr J R Stockton

    FAQ Dates; Opera Dates.

    Dr J R Stockton, Jun 18, 2007, in forum: Javascript
    Replies:
    0
    Views:
    179
    Dr J R Stockton
    Jun 18, 2007
Loading...

Share This Page