Julian Posted April 24, 2008 Share Posted April 24, 2008 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 More sharing options...
947740 Posted April 24, 2008 Share Posted April 24, 2008 The problem with that is the way MySQL stores the dates. They are not in a comparable format. They easy way would be to compare the timestamps. You will then have to convert the output, but you will be able to sort the content easily. Link to comment https://forums.phpfreaks.com/topic/102808-nearest-date/#findComment-526621 Share on other sites More sharing options...
Julian Posted April 25, 2008 Author Share Posted April 25, 2008 hi. Thanks for looking. Can you explain that using code? Regards Link to comment https://forums.phpfreaks.com/topic/102808-nearest-date/#findComment-526734 Share on other sites More sharing options...
947740 Posted April 25, 2008 Share Posted April 25, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.