jesushax Posted June 11, 2008 Share Posted June 11, 2008 hi heres my sql $PortSQL = mysql_query("SELECT * FROM tblPortfolio WHERE PortCurrent='0' ORDER BY PortDateAdded DESC") or die(mysql_error()); when i get my result the dates go like such 21/02/08 20/09/07 18/02/08 17/01/08 10/11/07 so its going 21,20,18,17,10 not by actual date, is this becuase my field type is not date? Link to comment https://forums.phpfreaks.com/topic/109718-solved-ordering-by-date-desc-is-going-by-the-first-number/ Share on other sites More sharing options...
MadTechie Posted June 11, 2008 Share Posted June 11, 2008 is this becuase my field type is not date? Yep Link to comment https://forums.phpfreaks.com/topic/109718-solved-ordering-by-date-desc-is-going-by-the-first-number/#findComment-562978 Share on other sites More sharing options...
jesushax Posted June 11, 2008 Author Share Posted June 11, 2008 its changed all my dates to 2021-02-08 2020-09-07 2018-02-08 2017-01-08 2010-11-07 and i cant manually change them back does it have to be Year month day? in mysql then you format it with code? Link to comment https://forums.phpfreaks.com/topic/109718-solved-ordering-by-date-desc-is-going-by-the-first-number/#findComment-562984 Share on other sites More sharing options...
MadTechie Posted June 11, 2008 Share Posted June 11, 2008 Okay, change it back and try this 1. rename the current date field to olddate 2. create a new field called newdate 3. query this (update table to the table name) UPDATE table SET newdate = STR_TO_DATE(olddate, '%d/%m/%Y'); 4. check the values of newdate Note always keep a backup Link to comment https://forums.phpfreaks.com/topic/109718-solved-ordering-by-date-desc-is-going-by-the-first-number/#findComment-562993 Share on other sites More sharing options...
jesushax Posted June 11, 2008 Author Share Posted June 11, 2008 ok got that so the newdates are all in the yyyy-mm-dd format and in my php code what do i use to format the date? thanks Link to comment https://forums.phpfreaks.com/topic/109718-solved-ordering-by-date-desc-is-going-by-the-first-number/#findComment-562998 Share on other sites More sharing options...
jesushax Posted June 11, 2008 Author Share Posted June 11, 2008 created a function to do it function mydate($record){ $date = strtotime($record); echo date('d/m/y',$date); } Link to comment https://forums.phpfreaks.com/topic/109718-solved-ordering-by-date-desc-is-going-by-the-first-number/#findComment-563017 Share on other sites More sharing options...
PFMaBiSmAd Posted June 11, 2008 Share Posted June 11, 2008 You can use the mysql DATE_FORMAT() function in your SELECT query to format a standard DATE or DATETIME any way you want. No php code is necessary. Link to comment https://forums.phpfreaks.com/topic/109718-solved-ordering-by-date-desc-is-going-by-the-first-number/#findComment-563211 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.