Todd W wrote:
"Jason Balicki" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

Hi,

I've got a phone record that keeps the date and time
in the following format:

         YYMMDDHHMM
example:  0501201500

So, I've written the following to convert it to the
format:

         MM/DD/YYYY,HH:MM
example:  01/20/2005,15:00



<snip />

This works, but strikes me as ugly.  Is there a more
elegant way of doing what I've done here?  It seems
like I should be able to loop through the $ardate[n]
entries and select them somehow instead of hard coding
the indexes, but nothing is coming to mind.



You want to use the C strptime finction. Theres several ways to use it
inside perl. I like Time::Piece:

[EMAIL PROTECTED] trwww]$ perl
use warnings;
use strict;

use Time::Piece;

my $time = Time::Piece->strptime('0501201500','%y%m%d%H%M');
print $time->datetime, "\n";
Ctrl-D
2005-01-20T15:00:00

Install and read the docs for Time::Piece.

Nice, Todd, I'd forgotten about that one.

I would like to add one thing however; that it might be preferable to YYYY-MM-DD,HH:MM the time unless you for whatever reasons will only be using the converted date for display purposes and not sorting purposes once it's been reformatted to your liking. Additionally, this format is not ambiguous to those from other countries who sometimes write DD/MM/YY or MM/DD/YY and may mis-read the dates there. YYYY-MM-DD is a well known format that disambiguates this confusion.


-- Scott R. Godin Laughing Dragon Services www.webdragon.net

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to