thereaper87 Posted October 4, 2011 Share Posted October 4, 2011 Hello there, this is more of a me trying to get my mind around it, more than it is a coding problem. I have a list in a database table that has a data on it in the format: mm/dd/yyyy I am trying to get the closest date from today. So today is the 4th, and the next date in the table is October 12, but when it is the 13th, it should get the next date automatically. I can't seem to figure out what coding structure to use. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/248423-getting-upcoming-date/ Share on other sites More sharing options...
Pikachu2000 Posted October 4, 2011 Share Posted October 4, 2011 You should store dates in the proper format, which is YYYY-MM-DD in a DATE or DATETIME type field in the database so you can use the date and time functions that are available to you without having to jump through hoops to do so. Quote Link to comment https://forums.phpfreaks.com/topic/248423-getting-upcoming-date/#findComment-1275737 Share on other sites More sharing options...
thereaper87 Posted October 5, 2011 Author Share Posted October 5, 2011 Great, thank you for your help! For others that come across this thread, this is what I used, and it works! mysql_query("(SELECT * FROM `schedule` WHERE `date` < NOW() ORDER BY `date` DESC LIMIT 1) UNION ( SELECT * FROM `schedule` WHERE `date` > NOW() ORDER BY `date` ASC LIMIT 1)") or die("error"); Quote Link to comment https://forums.phpfreaks.com/topic/248423-getting-upcoming-date/#findComment-1275868 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.