felipeebs Posted June 7, 2008 Share Posted June 7, 2008 How to parse mysql dates (YYYY-MM-DD HH:II:SS) into a date("d/m/Y H:i:s") format? <?php //mysql_query and all stuff date("d/m/Y H:i:s", $mysql_date_result); // This do not work for me ?> Link to comment https://forums.phpfreaks.com/topic/109086-solved-date-format/ Share on other sites More sharing options...
digitalgod Posted June 7, 2008 Share Posted June 7, 2008 you mean from a datetime field? SELECT date_format( yourcolumn, '%c/%e/%Y %T' ) FROM table Link to comment https://forums.phpfreaks.com/topic/109086-solved-date-format/#findComment-559615 Share on other sites More sharing options...
felipeebs Posted June 7, 2008 Author Share Posted June 7, 2008 is there any faster way to call the result, I mean: $sql = "SELECT *, date_format(date, '%d/%m/%Y %T') FROM eyetest ORDER BY id DESC"; $query = mysql_query($sql); while($n = mysql_fetch_assoc($query)){ echo $n["id"].' | '; echo $n["date"].' | '; echo $n["date_format(date, '%d/%m/%Y %T')"].'<br />'; print_r($n); } prints this: 2 | 2008-06-07 06:08:07 | 07/06/2008 06:08:07 1 | 2008-06-07 06:08:03 | 07/06/2008 06:08:03 I had to call $n["$n["date_format(date, '%d/%m/%Y %T')"] Anything to simplify this? Thanks Link to comment https://forums.phpfreaks.com/topic/109086-solved-date-format/#findComment-559770 Share on other sites More sharing options...
T Horton Posted June 7, 2008 Share Posted June 7, 2008 Hi Check this post I have just responded to. Sounds identical. http://www.phpfreaks.com/forums/index.php/topic,200651.0.html Any probs, shout. Best Regards Tom Link to comment https://forums.phpfreaks.com/topic/109086-solved-date-format/#findComment-559775 Share on other sites More sharing options...
felipeebs Posted June 7, 2008 Author Share Posted June 7, 2008 That is it! strtotime is just what I needed! Thank you! [solved] Link to comment https://forums.phpfreaks.com/topic/109086-solved-date-format/#findComment-559777 Share on other sites More sharing options...
felipeebs Posted June 12, 2008 Author Share Posted June 12, 2008 I'm sorry for reviving this topic, but I found the query simpler way with this $results = mysql_fetch_assoc(mysql_query("SELECT date_format(date, '%M %d %Y %H:%i') as date FROM table")); print_r($results); will return Array ( [date] => June 14 2008 14:08 ) conclusion: SQL code "SELECT date_format(column, format)" can receive the keyword "as var", so it do not returns $results[date_format(date, '%M %d %Y %H:%i')] = ... but returns $results[var] = ... I'm sorry again, but this may be usefull for someone else. Link to comment https://forums.phpfreaks.com/topic/109086-solved-date-format/#findComment-564067 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.