CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
How do I get a 2 digit month?



Apr 29, 2001, 2:55 AM

Post #1 of 2 (161 views)
How do I get a 2 digit month? Can't Post

Hi all. I'm trying to make a small modification to a perl script someone else wrote, and I'm having trouble. I'm not a programmer, but I have studied it a bit. I'm using the localtime() function in this script to help name files created by the script in the format: $month$day$hour$min. The script works fine, except that the month is represented as a single digit (0-11) instead of 2 digits. The program I'm trying to use this script with requires a two-digit month as part of the filename. Any suggestions on how I can get this to work? Thanks,



Apr 29, 2001, 5:26 AM

Post #2 of 2 (158 views)
Re: How do I get a 2 digit month? [In reply to] Can't Post


my $filename = sprintf("% 02d% 02d% 02d% 02d", $month+1, $day, $hour, $min); # Remove the space chars between percent sign(%) and the zero (0)

This will put all the variables as two-digit numbers in a string simultaneously adding 1 to the month value in order for it to be in range 1-12 and not 0-11.

Jean Spector
QA Engineer @ Extent Technologies, Ltd.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives