Solved

localtime format as "1999-01-28"

Posted on 1999-01-28
9
274 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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