drummer101 Posted January 11, 2008 Share Posted January 11, 2008 Well I didn't do such a great job designing one of my code snippets, and ended up storing the date in plain text, e.g. 1/10/2008, what would be the best way to store dates in the DB so they are easy to manipulate. I've created a new field on the table, type = date and I'm curious what I would use on the PHP side to properly format the input for the database. the date type is formatted yyyy-mm-dd, would date(Y-m-d) be the correct way to go about this or is there an easier way? Once stored, would explode() be the optimal way to get the date back into a mm-dd-yyyy format? Quote Link to comment https://forums.phpfreaks.com/topic/85495-solved-sql-sorting-by-date/ Share on other sites More sharing options...
rajivgonsalves Posted January 11, 2008 Share Posted January 11, 2008 you can order by str_to_date(datefield,'%m/%d/%Y'); assuming that your date format is mm/dd/yyyy Quote Link to comment https://forums.phpfreaks.com/topic/85495-solved-sql-sorting-by-date/#findComment-436309 Share on other sites More sharing options...
priti Posted January 11, 2008 Share Posted January 11, 2008 Well I didn't do such a great job designing one of my code snippets, and ended up storing the date in plain text, e.g. 1/10/2008, what would be the best way to store dates in the DB so they are easy to manipulate. I've created a new field on the table, type = date and I'm curious what I would use on the PHP side to properly format the input for the database. the date type is formatted yyyy-mm-dd, would date(Y-m-d) be the correct way to go about this or is there an easier way? Once stored, would explode() be the optimal way to get the date back into a mm-dd-yyyy format? Hi drummer, First thing when ever you are saving your date use the data type Date or datetime.And i will suggest you to use date_format() function of mysql while saving the date in the required format or while retrieve. Regards Quote Link to comment https://forums.phpfreaks.com/topic/85495-solved-sql-sorting-by-date/#findComment-436361 Share on other sites More sharing options...
drummer101 Posted January 11, 2008 Author Share Posted January 11, 2008 Awesome, thank you both so much. Quote Link to comment https://forums.phpfreaks.com/topic/85495-solved-sql-sorting-by-date/#findComment-436822 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.