Solved

localtime format as "1999-01-28"

Posted on 1999-01-28
9
280 Views
Last Modified: 2010-03-05
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
0
Comment
Question by:rickyr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 4

Expert Comment

by:martinag
ID: 1210350
@time = localtime;
$DATE = sprintf "%d-%02d-%02d", $time[5]+1900, $time[4]+1, $time[3];

Martin
0
 
LVL 4

Expert Comment

by:martinag
ID: 1210351
Or to make it a one-liner...
$DATE = sprintf "%d-%02d-%02d", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3];

Martin
0
 
LVL 84

Expert Comment

by:ozo
ID: 1210352
#also:
use POSIX;
$DATE = strftime("%Y-%m-%d",localtime);
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Expert Comment

by:ozo
ID: 1210353
#another one-liner:
$DATE = sprintf"%d-%02d-%02d",map{$_+(0,1,1900)[-(?^?..!??)]}(localtime)[5,4,3];
0
 
LVL 3

Author Comment

by:rickyr
ID: 1210354
hi....
I've been using the POSIX one, mainly coz I wanted to add %H-%M-%S for the tme aswell.
thanx, please answer.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1210355
$time=sprintf"%02d-%02d-%02d",(localtime)[2,1,0];
#or
use POSIX;
$time=strftime("%H-%M-%S",localtime);
#or
$time = join'-',(split/\W/,localtime)[3..5];
0
 
LVL 3

Author Comment

by:rickyr
ID: 1210356
Thanx ozo, but I meant re-post as an answer.

0
 
LVL 3

Author Comment

by:rickyr
ID: 1210357
0
 
LVL 84

Accepted Solution

by:
ozo earned 10 total points
ID: 1210358
answer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question