Jump to content

[SOLVED] Date formatting


smc

Recommended Posts

Hiya,

Okay I've been googling for about 3 hours and have been at a loss for this.

I have found the PHP.net entry on formatting the date using date() but my problem is I need it to format the date FROM the date(); function after it was inject into the db.

ie. I need to format the date from my MySQL database into terms such as "January 26th, 2006 @ 7:53PM EST"

How would I go about doing that?
Link to comment
Share on other sites

If you want to store the current time (when the insert happens) your best off to use mysql's NOW() function. eg;

[code]
INSERT INTO tbl (stamp) VALUES (NOW());
[/code]

Otherwise, take a look at the rest of mysql's date / time functions [url=http://mysql.org/doc/refman/5.0/en/date-and-time-functions.html]here[/url].
Link to comment
Share on other sites

The one I posted for you will, yes.
If you need to format time from a timestamp into mysql datetime format, just use date();
so say you want to put yesterday's date in the db.
$yesterday = time()-(60*60*24);
$str = date("Y-m-d H:i:s", $yesterday);
$sql = "INSERT INTO table(yourDate) VALUES('$str')";
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.