rickyr
asked on
localtime format as "1999-01-28"
Hi.......
I am using ....
$DATE = (join'-',(split/ /,localtime)[4,1,2]);
this returns "1999-Jan-28", but I need the Month to be a digit. "1999-01-28".
regards
I am using ....
$DATE = (join'-',(split/ /,localtime)[4,1,2]);
this returns "1999-Jan-28", but I need the Month to be a digit. "1999-01-28".
regards
Or to make it a one-liner...
$DATE = sprintf "%d-%02d-%02d", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3];
Martin
$DATE = sprintf "%d-%02d-%02d", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3];
Martin
#also:
use POSIX;
$DATE = strftime("%Y-%m-%d",localt ime);
use POSIX;
$DATE = strftime("%Y-%m-%d",localt
#another one-liner:
$DATE = sprintf"%d-%02d-%02d",map{ $_+(0,1,19 00)[-(?^?. .!??)]}(lo caltime)[5 ,4,3];
$DATE = sprintf"%d-%02d-%02d",map{
ASKER
hi....
I've been using the POSIX one, mainly coz I wanted to add %H-%M-%S for the tme aswell.
thanx, please answer.
I've been using the POSIX one, mainly coz I wanted to add %H-%M-%S for the tme aswell.
thanx, please answer.
$time=sprintf"%02d-%02d-%0 2d",(local time)[2,1, 0];
#or
use POSIX;
$time=strftime("%H-%M-%S", localtime) ;
#or
$time = join'-',(split/\W/,localti me)[3..5];
#or
use POSIX;
$time=strftime("%H-%M-%S",
#or
$time = join'-',(split/\W/,localti
ASKER
Thanx ozo, but I meant re-post as an answer.
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$DATE = sprintf "%d-%02d-%02d", $time[5]+1900, $time[4]+1, $time[3];
Martin