Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2010-09-09
3
Medium Priority
?
447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 1332 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 668 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 1332 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

Technology Partners: 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

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 …
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…
Six Sigma Control Plans

636 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