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
https://forums.phpfreaks.com/topic/35900-solved-date-formatting/
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].
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')";

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.