bubbadawg Posted February 4, 2009 Share Posted February 4, 2009 What's the best way to convert a date formatted as mm/dd/yyyy to a format that can be stored in mySQL (yyyy-mm-dd). The reason I want to convert is that when pulling the data back out of the database I need to sort it on date. If there is a better way to do this I am open to that as well. Thanks for any and all replies. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 4, 2009 Share Posted February 4, 2009 Assuming that you have validated the original format and value (which you should always do for external data), use the mysql STR_TO_DATE function in your query - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_str-to-date Quote Link to comment Share on other sites More sharing options...
bubbadawg Posted February 4, 2009 Author Share Posted February 4, 2009 Perfect thanks. I am using a date control in Flex so there should be no issue with validating the date. Quote Link to comment Share on other sites More sharing options...
bubbadawg Posted February 4, 2009 Author Share Posted February 4, 2009 One additional question. How about the inverse, retrieving the date from the database and converting it to a different format? Would I need to do that in the SQL statement or change the format via php? Thanks. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 4, 2009 Share Posted February 4, 2009 http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format Quote Link to comment 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.