piet Posted January 14, 2008 Share Posted January 14, 2008 i have a little problem, i need to order a query by date. but in the db, the date field is formulated "14.01.2008" instead of "2008.01.14" so the result is my output is all scrambled. i have alot of other scripts reading from this db so changing the field is not an option as it will mess up the other scripts. is there somrthing in the php query that i can add to output that data corectly? thanks Piet Quote Link to comment https://forums.phpfreaks.com/topic/85919-order-by-date-desc/ Share on other sites More sharing options...
dooper3 Posted January 14, 2008 Share Posted January 14, 2008 Something like the code shown below would rearrange the date AFTER you have extracted all the rows from the db. function rearrange($date) { $parts=explode(".", $date); $newdate=$date[3].".".$date[2].".".$date[1]; } As for changing the way you query the db, I really think to make it simpler in the long run it's easier to change the column in the database, after all you can always call a common function from every other php file that needs the date to arrange the date in the way you normally use it. Quote Link to comment https://forums.phpfreaks.com/topic/85919-order-by-date-desc/#findComment-438663 Share on other sites More sharing options...
rajivgonsalves Posted January 14, 2008 Share Posted January 14, 2008 use str_to_date function in mysql order by str_to_date(fieldname,"%d.%m.%Y") Quote Link to comment https://forums.phpfreaks.com/topic/85919-order-by-date-desc/#findComment-438683 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.