Solved

Perl, create a perl date object with date string of several formats

Posted on 2010-09-09
3
416 Views
Last Modified: 2012-06-21
I would like to create a perl date object with date string of several formats like 2/2/10, 02/02/10, where field is (month/day/year).

 
0
Comment
Question by:rgbcof
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 333 total points
ID: 33642790
POSIX::strftime can convert a time_t into any of several formats.
Date::Manip can do pretty much any date/time operation you could ever want.
0
 
LVL 30

Assisted Solution

by:Brad Howe
Brad Howe earned 167 total points
ID: 33642809
Why not just use the Date::format function?
http://datetime.perl.org/?Modules 
http://search.cpan.org/~gbarr/TimeDate-1.20/lib/Date/Format.pm 
#!/usr/bin/perl
use date::format;

print time2str("%D", time), "\n";
# (prints 09/09/10)

print time2str("%m/%d/%Y", time), "\n";
# (prints 09/09/2010)  
-Hades666
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 333 total points
ID: 33642961
If you want to convert from strings of several formats, Date::Manip can do that too,
although if you don't need all of Date::Manip's funtions, Date::Parse is a simpler module that also parses several date formats.
If all you need is month/day/year, then it may be easier to convert it yourself with POSIX::mktime
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delete query using perl dbi 3 100
crawling gofundme 4 126
perl to convert excel to csv 3 206
how to print sub line with  sed /awk /perl in bash file 11 22
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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

815 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