in reply to Working with date

I have to recommend looking at some date modules on cpan but there are a lot to choose from so if that is all you need to do, and all you'll ever need to do you could use something like this:

#!/usr/bin/perl -w use strict; my $time = time; my $date = date_format($time); print "Now: $date\n"; my $tendays = date_format( $time + ( 10 * 24 * 60 * 60 ) ); print "10 days from now: $tendays\n"; my $thirtydays = date_format( $time + ( 30 * 24 * 60 * 60 ) ); print "30 days from now: $thirtydays\n"; sub date_format{ my $seconds = shift; my @bits = localtime($seconds); $bits[4]++; $bits[5] += 1900; return sprintf "%02.0f-%02.0f-%04.0f %02.0f:%02.0f:%02.0f", ($bits[3 +],$bits[4],$bits[5],$bits[2],$bits[1],$bits[0]); }

my sprintf'n prolly isn't the best, but it seems to work..

cheers,

J

Replies are listed 'Best First'.
Re: Re: Working with date
by sauoq (Abbot) on Jun 04, 2003 at 06:31 UTC
    my sprintf'n prolly isn't the best, but it seems to work.

    Since you are printing integers, you should really use %d rather than %f. That and an array slice clean it up nicely...

    sprintf "%02d-%02d-%04d %02d:%02d:%02d", @bits[3,4,5,2,1,0];

    -sauoq
    "My two cents aren't worth a dime.";
    

      ahh, much better! ++

      cheers,

      J

Re: Re: Working with date
by alk1000 (Initiate) on Jun 06, 2003 at 01:14 UTC
    TANX mate, u're a star!