use strict; use Time::Local; my $date = "09/23/2003 14:30"; printf "%s\n", &date_to_unix($date); printf "%s\n", &get_date(&date_to_unix($date)); exit(0); sub date_to_unix() { my ($mon,$day,$year,$hour,$min) = $_[0] =~ /(\d+)\/(\d+)\/(\d+)\s(\d+):(\d+)/; return undef unless ($day and $mon and $year); return timelocal(0,$min,$hour,$day,$mon-1,$year-1900); } sub get_date() { my $time = shift || time(); my ($sec, $min, $hour, $day, $mon, $year) = localtime($time); # use sprintf to do string formatting for you in one go. # %02d will print digit preceeded with 0 if less than 10 and so on... return sprintf "%02d/%02d/%04d %02d:%02d", $mon+1, $day, $year+1900, $hour, $min; }