Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Date format question

by athomason (Curate)
on Sep 12, 2000 at 03:16 UTC ( #32018=note: print w/ replies, xml ) Need Help??


in reply to Date format question

printf and more generally sprintf allow you to specify how wide you want fields to print. printf just takes the string returned by sprintf and actually prints it, but the format specifiers are documented with sprintf. Try this:

printf("%4d.%02d.%02d\n", $year, $month, $day);

Update:

As BlaisePascal points out, this snippet assumes that the variables already contain what you want to print out; you may need to coerce return values from time functions to get them into the appropriate form.


Comment on Re: Date format question
Select or Download Code
RE: Re: Date format question
by BlaisePascal (Monk) on Sep 12, 2000 at 03:19 UTC
    Try:
    printf("%4d.%02d.%02d\n",$year+1900,$month,$day);
    That is, if you don't want today's date to be printed as 100.09.11

    You might want to use sprintf if you are trying to get it in a string.

      Actually, you'll also want to use $month+1...

      printf("%4d.%02d.%02d\n",$year+1900,$month+1,$day);

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2014-08-21 07:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (128 votes), past polls