how to get tomorrow date using Date::CALC

Discussion in 'Perl Misc' started by Bob, Sep 1, 2005.

  1. Bob

    Bob Guest

    want to take a date and return tomorrow's date..
    How to convert $tomorrow back to YY-MM-DD format?
    What is the inverse of Date_to_Days ?


    ... perl2.pl ---------------------------
    use strict; use warnings; use Date::Calc qw:)all);

    my ($yr2, $mon2, $day2, $tomorrow); my ($year, $month, $day);
    $yr2 = 2005; $mon2 = 3; $day2 = 20;

    print (" date- year: $yr2 month: $mon2 day:$day2 \n");
    $tomorrow = Date_to_Days($yr2,$mon2,$day2) + 1;
    print ("tomorrow: $tomorrow \n");

    ($year,$month,$day) = Today([$tomorrow]);
    print ("tommorow- year: $year month: $month day:$day \n");
    ------------------------------------------------------------------

    output ------------------------------------
    D:\edu\lrn\perl\date>perl date2.pl
    date- year: 2005 month: 3 day:20
    tomorrow: 732026
    tommorow- year: 2005 month: 9 day:1
     
    Bob, Sep 1, 2005
    #1
    1. Advertising

  2. Bob

    Paul Lalli Guest

    Bob wrote:
    > want to take a date and return tomorrow's date..
    > How to convert $tomorrow back to YY-MM-DD format?
    > What is the inverse of Date_to_Days ?


    Did you even *try* to look for this answer on your own? Say, in the
    documentation for the function you're using, of the module you're
    using?

    Straight out of perldoc Date::Calc's Date_to_Days() section :
    In order to convert the number returned by this function back into a
    date, use the function "Add_Delta_Days()" (described further below), as
    follows:

    $days = Date_to_Days($year,$month,$day);
    ($year,$month,$day) = Add_Delta_Days(1,1,1, $days - 1);

    Please make an attempt to help yourself before asking hundreds of
    people around the world to read documentation to you.

    > .. perl2.pl ---------------------------
    > use strict; use warnings; use Date::Calc qw:)all);
    >
    > my ($yr2, $mon2, $day2, $tomorrow); my ($year, $month, $day);
    > $yr2 = 2005; $mon2 = 3; $day2 = 20;


    GAAAH. What do you have against newlines?

    >
    > print (" date- year: $yr2 month: $mon2 day:$day2 \n");
    > $tomorrow = Date_to_Days($yr2,$mon2,$day2) + 1;
    > print ("tomorrow: $tomorrow \n");
    >
    > ($year,$month,$day) = Today([$tomorrow]);


    What made you think the Today() function takes a number of days as an
    argument? The docs say:
    ========================================
    # ($year,$month,$day) = Today([$gmt]);

    <...>

    If the optional (boolean) input parameter "$gmt" is given, a "true"
    value ("1") will cause "gmtime()" to be used instead of "localtime()",
    internally, thus returning Greenwich Mean Time (GMT, or UTC) instead of
    local time.
    =======================================

    Nothing about this function says that it returns anything other than
    *today*'s date.

    Paul Lalli
     
    Paul Lalli, Sep 1, 2005
    #2
    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. tertius

    date diff calc

    tertius, Nov 29, 2004, in forum: Python
    Replies:
    9
    Views:
    618
    David Fraser
    Dec 2, 2004
  2. craig
    Replies:
    0
    Views:
    343
    craig
    Apr 10, 2008
  3. craig
    Replies:
    0
    Views:
    375
    craig
    Apr 10, 2008
  4. Kaye Ng

    ruby calc.rb or just calc.rb

    Kaye Ng, Jul 26, 2010, in forum: Ruby
    Replies:
    7
    Views:
    432
    Kaye Ng
    Jul 28, 2010
  5. Fran?ois Laroche

    get date of tomorrow, need help

    Fran?ois Laroche, May 4, 2004, in forum: Javascript
    Replies:
    17
    Views:
    205
Loading...

Share This Page