downah Posted March 28, 2012 Share Posted March 28, 2012 I have got a date field in my mysql database with events, and as you know date in MYSQL uses yyyy/mm/dd but I would first like to turn this around to dd/mm/yyyy but also turn this into for example "Tuesday - May 1990" would anyone like to point me into the right direction? Much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/259866-turning-date-fields-into-actual-dates/ Share on other sites More sharing options...
AyKay47 Posted March 28, 2012 Share Posted March 28, 2012 In the SQL, use UNIX_TIMESTAMP() to convert the daytime field to a TIMESTAMP, then use the php function date to format it. Quote Link to comment https://forums.phpfreaks.com/topic/259866-turning-date-fields-into-actual-dates/#findComment-1331840 Share on other sites More sharing options...
downah Posted March 28, 2012 Author Share Posted March 28, 2012 Thanks for the help, at the moment I am first trying to turn yyyy/mm/dd around to dd/mm/yyyy with this: $date = $row['eventdate']; echo "<td>" . date('d-m-Y',$date) . " " . $row['starttime'] . "</td>"; which puts it into dd/mm/yyyy great! although it is not showing the right dates! but automatically all dates seemed to change to 01/01/1970.. know why? Quote Link to comment https://forums.phpfreaks.com/topic/259866-turning-date-fields-into-actual-dates/#findComment-1331846 Share on other sites More sharing options...
AyKay47 Posted March 28, 2012 Share Posted March 28, 2012 Re-read my first reply, the date() function requires a TIMESTAMP as the second argument. You need to convert the datetime field into a TIMESTAMP using unix_timestamp() Quote Link to comment https://forums.phpfreaks.com/topic/259866-turning-date-fields-into-actual-dates/#findComment-1331850 Share on other sites More sharing options...
litebearer Posted March 28, 2012 Share Posted March 28, 2012 easier to use mysql's date formating function http://www.electrictoolbox.com/article/mysql/format-date-time-mysql/ Quote Link to comment https://forums.phpfreaks.com/topic/259866-turning-date-fields-into-actual-dates/#findComment-1331852 Share on other sites More sharing options...
downah Posted March 28, 2012 Author Share Posted March 28, 2012 $date = $row['eventdate']; $my_date = strtotime($date); echo "<td>" . date('d-m-Y',$my_date) . " " . $row['starttime'] . "</td>"; Mmm I thought this would do it, but still showing the 01-01-1970 Quote Link to comment https://forums.phpfreaks.com/topic/259866-turning-date-fields-into-actual-dates/#findComment-1331853 Share on other sites More sharing options...
downah Posted March 28, 2012 Author Share Posted March 28, 2012 I got it to work using: echo "<td>"; print date('d M Y', strtotime($row['eventdate'])); echo " "; echo $row['starttime'] . "</td>"; Thanks guys, although I'd still like to know why this doesn't work if anyone could point that out? $date = $row['eventdate']; $my_date = strtotime($date); echo "<td>" . date('d-m-Y',$my_date) . " " . $row['starttime'] . "</td>"; Quote Link to comment https://forums.phpfreaks.com/topic/259866-turning-date-fields-into-actual-dates/#findComment-1331855 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.