Jump to content

strtotime problem help!


warpdesign

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?
Link to comment
https://forums.phpfreaks.com/topic/19238-strtotime-problem-help/
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.
Link to comment
https://forums.phpfreaks.com/topic/19238-strtotime-problem-help/#findComment-83332
Share on other sites

Archived

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

×
×
  • Create New...

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.