Jump to content

Nearest date


Julian

Recommended Posts

Hi guys

 

I have this problem and I think may you can help me.

 

I have events stores on MySQL database each event have startdate stored as `date`.

 

I want to show the current event or the closest event.  In my query I'm using:  WHERE `startdate` >= CURDATE()

 

The problem is this query doesn't show me the event for today it goes to the nearest event.  If I use:  WHERE `startdate` = CURDATE()

 

It show me the today events but not the nearest events.  I tried: WHERE `startdate` > CURDATE() or startdate` = CURDATE()

 

And got the nearest event but not the today events.  If anybody know how to solve this will be highly appreciate.

 

Regards

 

Julian

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/102808-nearest-date/
Share on other sites

To convert a date to a timestamp in PHP, use strtotime($date), where $date is the time you would like converted to a timestamp.

 

For your ease of use, you could have the timestamp, month, and year in your database to avoid having to convert every time you use information.  When you want to sort, you can sort by the timestamp, but when you want to use the info, you can take the month and year out of the table.

Link to comment
https://forums.phpfreaks.com/topic/102808-nearest-date/#findComment-527052
Share on other sites

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.