Jump to content

Getting upcoming date


thereaper87

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/248423-getting-upcoming-date/
Share on other sites

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.

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");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.