Solved

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

Posted on 2010-09-09
3
428 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

756 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