Solved

localtime format as "1999-01-28"

Posted on 1999-01-28
9
270 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl - Mawk 2 87
Perl Sort Question 4 129
batch script for automated email 12 100
Put query string from URL request -  PERL HTTP Daemon 2 72
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

919 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now