Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > To change the time stamp format...

Reply
Thread Tools

To change the time stamp format...

 
 
clearguy02@yahoo.com
Guest
Posts: n/a
 
      04-02-2005
Hi experts,

I need a function in my perl program that converts the given time stamp
to a specific time stamp format.

example: 15-Aug-04.19:03 should be converted to 2004-08-15 19:03:00

Can some one tell me how to do this?

Thanks,
John

 
Reply With Quote
 
 
 
 
Felix Geerinckx
Guest
Posts: n/a
 
      04-02-2005
On 02/04/2005, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> example: 15-Aug-04.19:03 should be converted to 2004-08-15 19:03:00
>
> Can some one tell me how to do this?


use split with /[-:.]/ to get the individual date parts
use a hash to translate month abbreviations to month numbers
use sprintf to format your target date

--
felix
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      04-02-2005
(E-Mail Removed) wrote:
> I need a function in my perl program that converts the given time stamp
> to a specific time stamp format.
>
> example: 15-Aug-04.19:03 should be converted to 2004-08-15 19:03:00
>
> Can some one tell me how to do this?


There are two approaches:

1) You can search for an applicable module at http://search.cpan.org/

2) You can write the function yourself. Useful built-in Perl functions
may be:

perldoc -f split
perldoc -f sprintf

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
clearguy02@yahoo.com
Guest
Posts: n/a
 
      04-02-2005
Thanks Felix,

Do you have any example code to do this?

Thanks,
John

 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      04-02-2005
[ Please give some context when you reply to a message. See the posting
guidelines for this group at
http://mail.augustmail.com/~tadmc/cl...uidelines.html ]

(E-Mail Removed) wrote:
> Felix Geerinckx wrote:
>>>
>>> example: 15-Aug-04.19:03 should be converted to 2004-08-15 19:03:00
>>>
>>> Can some one tell me how to do this?

>>
>> use split with /[-:.]/ to get the individual date parts
>> use a hash to translate month abbreviations to month numbers
>> use sprintf to format your target date

>
> Thanks Felix,
>
> Do you have any example code to do this?


Felix probably has code in his collection of Perl code snippets that
does exactly the convertion you need, and it was most likely through an
oversight he didn't post it along with the above hints.

If I'm wrong in my assumption, you may need to look up those parts of
the Perl documentation and give it a try yourself. Scaring thought, I
know, but what can you do...

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      04-02-2005
(E-Mail Removed) wrote:
>
> I need a function in my perl program that converts the given time stamp
> to a specific time stamp format.
>
> example: 15-Aug-04.19:03 should be converted to 2004-08-15 19:03:00
>
> Can some one tell me how to do this?



my $date = '15-Aug-04.19:03';

my %months = qw(
Jan 1
Feb 2
Mar 3
Apr 4
May 5
Jun 6
Jul 7
Aug 8
Sep 9
Oct 10
Nov 11
Dec 12
);

my $mon_lookup = join '|', keys %months;

if ( $date =~ /(\d+)-($mon_lookup)-(\d+)\.(\d+)\d+)/ ) {

printf "20%02d-%02d-%02d %02d:%02d:00\n", $3, $months{$2}, $1, $4, $5;

}




John
--
use Perl;
program
fulfillment
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      04-02-2005
"John W. Krahn" <(E-Mail Removed)> wrote in
news:C2F3e.127630$ZO2.8180@edtnps84:

> (E-Mail Removed) wrote:
>>
>> I need a function in my perl program that converts the given time
>> stamp to a specific time stamp format.
>>
>> example: 15-Aug-04.19:03 should be converted to 2004-08-15 19:03:00
>>
>> Can some one tell me how to do this?

>
>


> my $mon_lookup = join '|', keys %months;
>
> if ( $date =~ /(\d+)-($mon_lookup)-(\d+)\.(\d+)\d+)/ ) {
>
> printf "20%02d-%02d-%02d %02d:%02d:00\n", $3, $months{$2}, $1,
> $4, $5;


Ooops! How about that Y2.1K bug?!

Sinan

--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      04-02-2005
(E-Mail Removed) <(E-Mail Removed)> wrote:

> Thanks Felix,
>
> Do you have any example code to do this?



Post the code that you have tried so far, and we will help you fix it.


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      04-03-2005
A. Sinan Unur wrote:
> "John W. Krahn" <(E-Mail Removed)> wrote in
> news:C2F3e.127630$ZO2.8180@edtnps84:
>>
>>if ( $date =~ /(\d+)-($mon_lookup)-(\d+)\.(\d+)\d+)/ ) {
>>
>> printf "20%02d-%02d-%02d %02d:%02d:00\n", $3, $months{$2}, $1,
>> $4, $5;

>
> Ooops! How about that Y2.1K bug?!


Is that thing still around?


John
--
use Perl;
program
fulfillment
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      04-03-2005
"John W. Krahn" <(E-Mail Removed)> wrote in news:EEG3e.127836$ZO2.94802
@edtnps84:

> A. Sinan Unur wrote:
>> "John W. Krahn" <(E-Mail Removed)> wrote in
>> news:C2F3e.127630$ZO2.8180@edtnps84:
>>>
>>>if ( $date =~ /(\d+)-($mon_lookup)-(\d+)\.(\d+)\d+)/ ) {
>>>
>>> printf "20%02d-%02d-%02d %02d:%02d:00\n", $3, $months{$2}, $1,
>>> $4, $5;

>>
>> Ooops! How about that Y2.1K bug?!

>
> Is that thing still around?


Yeah, it seems like a new version is released every century

Sinan
--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date stamp and how to change on a doc.file vikingwoman61 General Computer Support 1 06-22-2009 02:08 AM
Saving time stamp for replied to email? Keith Firefox 4 01-17-2006 07:03 PM
Modifying a file's time stamp ladygrinningsoul Perl 1 12-06-2004 02:36 AM
Can Windows file time stamp be changed to shooting time? Gustav Digital Photography 8 07-31-2004 10:11 PM
Date/Time stamp in SQL =?Utf-8?B?QmVydA==?= ASP .Net 2 01-30-2004 04:47 PM



Advertisments