in reply to Calculating date from a fixed point

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

Replies are listed 'Best First'.
Re: Re: Calculating date from a fixed point
by aschroh (Novice) on Apr 16, 2003 at 16:26 UTC
    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

        I am glad this helped.

        To keep the formatting you can use sprintf. (printf, "is equivalent to print FILEHANDLE sprintf(FORMAT, LIST), except that $\ ... is not appended").

        So your code would now look like this. :

        use Date::Calc qw/Add_Delta_Days/; my $delta = 72583; my ($year,$month,$day) = Add_Delta_Days(1800,12,28,$delta); $newdate = sprintf("%4d%02d%02d", $year, $month, $day); print "$newdate\n";

        -enlil