Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Perl (http://www.programmingforums.org/forum21.html)
-   -   How do I format a date like this? (http://www.programmingforums.org/showthread.php?t=13913)

BinkyM Sep 4th, 2007 11:51 PM

How do I format a date like this?
 
Hi, folks:

I have a date like this in my SQL database:

1105083432

I need it in this format for my RSS feed:

Sat, 07 Sep 2002 00:00:01 GMT

I don't know a whole lot about Perl, but when it comes to formatting dates, I just wanna roll over and die. I've trying googling Perl date formatting in all kinda ways, but I can't find anything that comes remotely close to anything I can use, and my eyes have glazed over and my brain is now all mushy. It doesn't help that I don't know what terminology to use to google what it is I'm trying to find! (I don't know what to call that date format!)

I would be *ever* so grateful for a clue before I rip all my hair out! Thanks!

Wizard1988 Sep 4th, 2007 11:54 PM

You may want to toy around with localtime() :)

grimpirate Sep 5th, 2007 12:10 AM

Don't know much about Perl but from the looks of it I would imagine that what the database is storing is Unix timestamps. So like Wizard1988 suggested there's probably a function which lets you format unix timestamps into a certain type of string.

BinkyM Sep 5th, 2007 12:26 AM

grimmy:

Quote:

there's probably a function which lets you format unix timestamps into a certain type of string
Oh, of course; I just needed a pointer to what, zactly, that'd be. Thanks to the Wiz, I located gmtime(), which is pretty close (I'll end up with "Thu Oct 13 04:54:34 1994" and then I'll hafta append the "GMT" to it, then I don't know what I'll do about getting the comma after the day of the week and then reordering the date), but I'm closer to where I was, which was off in Greenland somewhere. Now I'm at least at the Canadian border, trying to convince the authorities to let me cross in. ;-)

If anyone else has any further ideas while I hammer away at this, I'd sure like to hear 'em!

Thanks for getting me this far, folks!

BinkyM Sep 5th, 2007 12:34 AM

Oh, wait: I'm a big, fat Der!-head. I'm sposta be able to parse the various parts of the date out using gmtime()! I need to whack myself in the head with a hammer to reboot my brain. I think I just wored myself out today. Time to eat dinner and watch some TV, maybe look at it again tomorrow when I'm fresh and I can think better. Thanks, men! This oughtta do the trick. I appreciate it!

stevengs Sep 6th, 2007 3:52 PM

I would suggest the following:

use POSIX qw(strftime);

my $date_string = strftime "%a, %e %b %Y %H:%M:%S %Z", $TIMESTAMP;

or something to that nature.

see:
http://www.cppreference.com/stddate/strftime.html

cheers.
Steven

stevengs Sep 6th, 2007 3:54 PM

... substitute %d for %e, to get double-digit Day-Of-Month ;)

(my bad)


All times are GMT -5. The time now is 4:43 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC