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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.