only1perky Posted February 28, 2009 Share Posted February 28, 2009 Hi Guys, I am trying to take a data from my database which is set as a 'date' in 'yyyy-mm-dd' format. I would now like to query my database, but have the date echoed in the format 'dd-mm-yyyy'. I have searched through dozens of websites and I either get a date displayed as 01-01-1970 or a bunch of crazy error which confuses me beyond believe. Could someone please walk me through solving this. Thanks. Link to comment https://forums.phpfreaks.com/topic/147288-format-how-date-is-displayed/ Share on other sites More sharing options...
Mchl Posted February 28, 2009 Share Posted February 28, 2009 Only if you show some code of yours. Link to comment https://forums.phpfreaks.com/topic/147288-format-how-date-is-displayed/#findComment-773166 Share on other sites More sharing options...
only1perky Posted February 28, 2009 Author Share Posted February 28, 2009 At the moment I have this query to select all events which are currently open: $query_rsevents = "SELECT * FROM events where start_date <= NOW() AND end_date >= NOW()"; I am then simply echoing the results with: <strong>Start Date: </strong><?php echo ($row_rsevents['start_date']); ?> This works but obviously displays the date as yyyy-mm-dd as is the mysql date format. I would like it displayed as dd-mm-yyyy. Cheers. Link to comment https://forums.phpfreaks.com/topic/147288-format-how-date-is-displayed/#findComment-773171 Share on other sites More sharing options...
Mchl Posted February 28, 2009 Share Posted February 28, 2009 <?php echo date("d-m-Y",strtotime($row_rsevents['start_date'])); ?> Link to comment https://forums.phpfreaks.com/topic/147288-format-how-date-is-displayed/#findComment-773181 Share on other sites More sharing options...
shadiadiph Posted February 28, 2009 Share Posted February 28, 2009 a longer way around it i have been using is $rsevents = $row["rsevents"]; $date = explode("-","$rsevents"); $newdate = strftime("%d-%m-%Y",mktime(0,0,0,$date[1],$date[2],$date[0])); print $newdate; sorry but its the only way i know and then to store it again in the database have to explode it again and do the date arrays in a different order to put it back to yyyy-mm-dd format $date2 = explode("-","$newdate"); $newdate2 = strftime("%Y-%m-%d",mktime(0,0,0,$date2[1],$date2[0],$date2[2])); Link to comment https://forums.phpfreaks.com/topic/147288-format-how-date-is-displayed/#findComment-773217 Share on other sites More sharing options...
cooldude832 Posted February 28, 2009 Share Posted February 28, 2009 <?php echo date("d-m-Y",strtotime($row_rsevents['start_date'])); ?> preferred method, because of optimization is to actually allow MySQL to format the date. This is only preferred if you are only echoing out that date and not manipulating it further. More prefered is a UNIX time stamp as this removes the need to strtotime the value, and seconds are considered the lowest unit of manipulation in MySQL This will be useful to you http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format Link to comment https://forums.phpfreaks.com/topic/147288-format-how-date-is-displayed/#findComment-773218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.