simonp Posted August 14, 2009 Share Posted August 14, 2009 In my db I'm storing the date and time as date('YmdHi') eg: 200908141659 When I get the info from the db - I want to display it as: 16:59 14/08/2009 How would I go about doing that? Cheers Simon Quote Link to comment https://forums.phpfreaks.com/topic/170278-solved-date-and-time-conversion-question/ Share on other sites More sharing options...
JonnoTheDev Posted August 14, 2009 Share Posted August 14, 2009 Is there a reason for storing the date in this fashion. Really you should use an INT(10) and use a UNIX timestamp. This value can be converted back to date & time using php's date() function. Timestamp print time(); Quote Link to comment https://forums.phpfreaks.com/topic/170278-solved-date-and-time-conversion-question/#findComment-898223 Share on other sites More sharing options...
Daniel0 Posted August 14, 2009 Share Posted August 14, 2009 You should store it as a DATETIME field. You can do like this though: <?php $time = 200908141659; $unix = mktime(substr($time, 8, 2), substr($time, 10, 2), 0, substr($time, 4, 2), substr($time, 6, 2), substr($time, 0, 4)); echo date('H:i m/d/Y', $unix); Quote Link to comment https://forums.phpfreaks.com/topic/170278-solved-date-and-time-conversion-question/#findComment-898228 Share on other sites More sharing options...
simonp Posted August 14, 2009 Author Share Posted August 14, 2009 Thanks guys - went with the unix timestamp (time()) option (which I should have done in the first place!) All working. Cheers Simon Quote Link to comment https://forums.phpfreaks.com/topic/170278-solved-date-and-time-conversion-question/#findComment-898241 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.