Jump to content

Archived

This topic is now archived and is closed to further replies.

warpdesign

strtotime problem help!

Recommended Posts

Hello, I'm having problems using strtotime. I'm pulling dates from a database, the dates are in the format:
YYYY-MM-DD HH:MM:SS

I want to reformat it so it's more user friendly, i.e.
Sun, May 4 2006
4:30 PM

I thought I could do this using strtotime and then reformating the date, but I get a strange number when I convert the string using that. Something like 1156723200...

Do I then need to feed that number to another function? Also how do I convert it back to the original format to write back to the database?

Share this post


Link to post
Share on other sites
That 1156723200 is a [url=http://en.wikipedia.org/wiki/Unix_time]timestamp[/url].
You use it now with the [url=http://www.php.net/manual/en/function.date.php]date()[/url] function to make the date formatted nicely.

date("d, F jS Y, g:i A", $timestamp);
Will come out nicely, when $timestamp is your number you got from strtotime().
To format it back to your DB format, use date("Y-n-d H:i:s", $timestamp) ($timestamp is that number you got).

Orio.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.