Solved

localtime format as "1999-01-28"

Posted on 1999-01-28
9
267 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
Comment Utility
@time = localtime;
$DATE = sprintf "%d-%02d-%02d", $time[5]+1900, $time[4]+1, $time[3];

Martin
0
 
LVL 4

Expert Comment

by:martinag
Comment Utility
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
Comment Utility
#also:
use POSIX;
$DATE = strftime("%Y-%m-%d",localtime);
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
#another one-liner:
$DATE = sprintf"%d-%02d-%02d",map{$_+(0,1,1900)[-(?^?..!??)]}(localtime)[5,4,3];
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 3

Author Comment

by:rickyr
Comment Utility
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
Comment Utility
$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
Comment Utility
Thanx ozo, but I meant re-post as an answer.

0
 
LVL 3

Author Comment

by:rickyr
Comment Utility
0
 
LVL 84

Accepted Solution

by:
ozo earned 10 total points
Comment Utility
answer
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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

11 Experts available now in Live!

Get 1:1 Help Now