Solved

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

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

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 script help 5 232
cpan issue 1 61
Migrate OTRS to newest version. 1 309
Transforming a Soap message to a simple xml message! 10 143
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…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

932 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

14 Experts available now in Live!

Get 1:1 Help Now