merylvingien Posted January 22, 2010 Share Posted January 22, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/189448-output-date-and-time-from-database/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 22, 2010 Share Posted January 22, 2010 http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format Quote Link to comment https://forums.phpfreaks.com/topic/189448-output-date-and-time-from-database/#findComment-1000004 Share on other sites More sharing options...
wildteen88 Posted January 22, 2010 Share Posted January 22, 2010 Have a read of this article http://www.phpfreaks.com/tutorial/working-with-dates-in-php Quote Link to comment https://forums.phpfreaks.com/topic/189448-output-date-and-time-from-database/#findComment-1000006 Share on other sites More sharing options...
merylvingien Posted January 22, 2010 Author Share Posted January 22, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/189448-output-date-and-time-from-database/#findComment-1000022 Share on other sites More sharing options...
wildteen88 Posted January 22, 2010 Share Posted January 22, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/189448-output-date-and-time-from-database/#findComment-1000046 Share on other sites More sharing options...
merylvingien Posted January 22, 2010 Author Share Posted January 22, 2010 THATS IT Many thanks wildteen88 You are a star... Quote Link to comment https://forums.phpfreaks.com/topic/189448-output-date-and-time-from-database/#findComment-1000057 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.