aschroh has asked for the wisdom of the Perl Monks concerning the following question:

How would I calculate a date from a fixed point? For Example: Starting with day 1 being December 28, 1800 How would I figure out what day 72583 was in YYYYMMDD?

Replies are listed 'Best First'.
Re: Calculating date from a fixed point
by BrowserUk (Patriarch) on Apr 08, 2003 at 22:58 UTC

    One way.

    #! perl -slw use strict; use Date::Manip; print UnixDate( DateCalc( ParseDate('December 28, 1800') , '+72583 days') , '%Q'); __END__ C:\test>248106 19990919

    Examine what is said, not who speaks.
    1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
    2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
    3) Any sufficiently advanced technology is indistinguishable from magic.
    Arthur C. Clarke.

        I just got around to following the link you posted, and laughed myself silly.

        Thanks for lightening my day:)


        Examine what is said, not who speaks.
        1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
        2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
        3) Any sufficiently advanced technology is indistinguishable from magic.
        Arthur C. Clarke.
Re: Calculating date from a fixed point
by Enlil (Parson) on Apr 08, 2003 at 23:30 UTC
    Another way, using Date-Calc:
    use strict; use warnings; use Date::Calc qw/Add_Delta_Days/; my $delta = 72583; my ($year,$month,$day) = Add_Delta_Days(1800,12,28,$delta); printf "%4d%02s%02s",$year,$month,$day;
    -enlil
      Enlil, This method fit my needs perfectly thanks for your assistance =) aschroh
        Enlil,

        One More Question if you would allow me.

        How to push the result to a variable? I tried the following and it worked but the formatting was of course lost doing it this way.

        what I did

        use Date::Calc qw/Add_Delta_Days/; my $delta = 72583; my ($year,$month,$day) = Add_Delta_Days(1800,12,28,$delta); $newdate = $year$month$day; printf "$newdate \n";
        which gave me 1999919
        I need it to be YYYMMDD.

        How do I put this to a variable with the formatting you used?

        thanks for your great help =)

        aschroh

Re: Calculating date from a fixed point
by The Mad Hatter (Priest) on Apr 08, 2003 at 22:44 UTC
    Your best bet would be to use the various Date modules on CPAN. More specifically, take a look at Date::Manip and Date::Calc.

    Nota Bene I'm not sure if those modules can do what you want, but it'd probably be best to look there first.