Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

localetime

Status
Not open for further replies.

BryanY

MIS
Aug 18, 2001
54
US
I'm trying to store the date as a variable in the format dd-mm-yy. (Similar to date '+%m-%d-%y' in UNIX.)

Unfortunately when i use the localtime module it doesn't return the single digit days and months with a preceding zero.

(1-3-05 instead of 01-03-05) Is there a simple workaround for this? or should I use a different module?

(I suppose that using a system call would be a last resort.)
 
This should give you a good start:

Code:
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
$mon++; $year -= 100;
my $date = sprintf "%02i-%02i-%02i", $mon, $mday, $year;
print $date;
Which gives you the output:
Code:
01-03-05
You could also use the printf function to directly print the date without using the temporary variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top