Jump to content

Output date and time from database


merylvingien

Recommended Posts

Hi Fellas, having a bit of trouble getting the date and time to display correctly from database.

 

At the moment i have the date stored in the database as "datetime" and as an example it stores the date as "2010-01-19 17:01:11"

 

I want to output this on the page as  Tuesday 19 2010 @ 17:01 PM

 

But whatever i try it isnt having it.

 

Ive tried numerous things and googled lots, but i think my brain is fried now, and a little help would good.

Link to comment
https://forums.phpfreaks.com/topic/189448-output-date-and-time-from-database/
Share on other sites

Thanks for the links, but they arent helping.

 

I can store the date in the database fine.

I can also get the bloody date back out of the database, but when i want to add a "pm" or "am" is wont have it...

 

This must be done daily, so someone must know.

You can use strtotime to convert your mysql timestamp into a unix timestamp. Using the unix timstamp you can pass this into the secound parameter for the date function to reformatted your date. Example

 

$mysqlTimestamp = '2010-01-19 17:01:11';

$unixTimestamp = strtotime($mysqlTimestamp);

echo date('l jS Y h:i:s a', $unixTimestamp);

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.