Solved

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

Posted on 2010-09-09
3
394 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

16 Experts available now in Live!

Get 1:1 Help Now