Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Date format question

by BastardOperator (Monk)
on Sep 12, 2000 at 04:23 UTC ( [id://32036]=note: print w/replies, xml ) Need Help??


in reply to Date format question

Here's my 2 cents:
use POSIX qw(strftime); print strftime("%Y.%m.%d", localtime()), "\n";

small tip, use the system for dates, don't try to add and whatnot, what happens when it's the twelfth month?...you get 13.

Replies are listed 'Best First'.
RE: Re: Date format question
by Adam (Vicar) on Sep 12, 2000 at 04:27 UTC
    I always forget about the POSIX stuff, of course I also wish Perl had a matrix operator so that I could say something like:
    printf '%d,%02d,%02d', (1900,1,0) plus reverse +(localtime)[3..5];
    Er... I guess really that's just a vector operator... I know there are modules to do that, but I think it should be part of the Perl core... otherwise what's the point? I could just as easily write it:
    sub add_vectors { my @left = @{ shift }; my @right = @{ shift }; my @result = (); my $index = $#left > $#right ? @left : @right; while( --$index >= $[ ) { $left[$index] = 0 if not defined $left[$index]; $right[$index] = 0 if not defined $right[$index]; $result[$index] = $left[$index] + $right[$index]; } return \@result; }
    A sloppy first pass, but you get the idea.
RE: Re: Date format question
by le (Friar) on Sep 12, 2000 at 11:32 UTC
    If we're talking Perl, you won't get 13 if it is the twelfth month, because localtime delivers months from 0 to 11.

    Besides that I like your answer.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://32036]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-19 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found