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

Hi Fellow CubeDwellers;
I am using the following code to calculate the days from 1900.
I found the code somewhere, but it doesn't appear to work using the $ydays field.
I need to calculate the difference between 2 dates in days.
sub create_date { my ($sec, $min, $hour, $wday, $month, $year, $yday, $something) = loca +ltime(time()); $curyear = $year + 1900; $today = join "/",$wday,$month + 1,$curyear; $daysofyear = $year * 365; $daysthisyear = $yday; $daystonow = $daysofyear + $daysthisyear; }
Thanks
CubeDweller

Replies are listed 'Best First'.
Re: Counting the days from year 1900 to current
by CheeseLord (Deacon) on Aug 11, 2001 at 00:16 UTC

    This looks like a job for Date::Calc! (Available from your nearest neighborhood CPAN.)

    In all seriousness, though, you'll notice that you're not calculating leap days, and other annoying things that time has to deal with, which is why I recommend using the module. That said, the problem is likely in your assignment: yday is two fields after year, not one (it's at (localtime)[7]). Check out localtime for more info.

    Update: Added link to Date::Calc.

    His Royal Cheeziness

      That's great.

      You Guys are Great!!
      I am running on win32 version. How do I install the module? I've never done that before.

      Thanks in advance.
      CubeDweller
        Are you running cygwin or Activestate? With Activestate you can use the 'ppm' tool to install modules. With Cygwin I think you would want to download the tar ball and run the make; make install; but I haven't worked much with Cygwin's perl.

        Ira,

        "So... What do all these little arrows mean?"
        ~unknown

        if the modules isn't in activestate's archive, you'll need to find a copy of nmake.exe from microsoft to be able to create the makefile. do a web search and you should be able to come up with a copy. you'll also need to come up with a gcc-compatible compiler ... cygwin works and you can also download a kit that includes a compiler from borland. it's been a while since i worked through this, but you shouldn't have much trouble.
Re: Counting the days from year 1900 to current
by astaines (Curate) on Aug 11, 2001 at 03:27 UTC

    CPAN

    C:> perl -MCPAN -e shell cpan> ? ## How to get help in CPAN cpan> i /Date::Calc/ [Information on Date::Calc] cpan> install Date::Calc [Assorted messages] cpan> q ## How to get out of CPAN C:>

    or PPM

    C:>ppm ppm>help ## How to get help in ppm ppm> search Date::Calc [Information on Date::Calc surprisingly enough...] ppm> install Date::Calc [Assorted messages] ppm> exit ## How to get out of ppm

    Don't you just love consistency.. :-)
    Hope this helps.

    -- Anthony Staines