dadamssg Posted January 23, 2009 Share Posted January 23, 2009 i have a database that stores events. It has a start time and a end time in the DATETIME format. these events have the potential to span over a few days. If i want to select events that are going on today(12am-12:59pm) how do i write the query? Quote Link to comment https://forums.phpfreaks.com/topic/142189-solved-query-datetimes/ Share on other sites More sharing options...
Mchl Posted January 23, 2009 Share Posted January 23, 2009 WHERE DATE(startDate) <= CURDATE() AND DATE(endDate) >= CURDATE() Quote Link to comment https://forums.phpfreaks.com/topic/142189-solved-query-datetimes/#findComment-744840 Share on other sites More sharing options...
dadamssg Posted January 24, 2009 Author Share Posted January 24, 2009 awesome thanks! and if i want to request a day sometime in the future would just write out the specific date in the datetime format such as 2009-11-21 04:20:00? and if thats correct would i need to put that in parenthesis or anything? Quote Link to comment https://forums.phpfreaks.com/topic/142189-solved-query-datetimes/#findComment-744854 Share on other sites More sharing options...
Mchl Posted January 24, 2009 Share Posted January 24, 2009 You would either do WHERE DateTimeField = '2009-11-21 04:20:00' or WHERE DateTimeField = 20091121042000 Quote Link to comment https://forums.phpfreaks.com/topic/142189-solved-query-datetimes/#findComment-744863 Share on other sites More sharing options...
dadamssg Posted January 24, 2009 Author Share Posted January 24, 2009 thank you so much kind sir Quote Link to comment https://forums.phpfreaks.com/topic/142189-solved-query-datetimes/#findComment-744866 Share on other sites More sharing options...
Mchl Posted January 24, 2009 Share Posted January 24, 2009 You're welcome my good sir. (feeling imperial, are we?) Quote Link to comment https://forums.phpfreaks.com/topic/142189-solved-query-datetimes/#findComment-744868 Share on other sites More sharing options...
dadamssg Posted January 24, 2009 Author Share Posted January 24, 2009 wait on more quick question....how do i query if i pull up todays events and wanted them order from soonest to latest?? Quote Link to comment https://forums.phpfreaks.com/topic/142189-solved-query-datetimes/#findComment-744870 Share on other sites More sharing options...
xtopolis Posted January 24, 2009 Share Posted January 24, 2009 ORDER BY startDate ASC (order by events starting the soonest in the day) Quote Link to comment https://forums.phpfreaks.com/topic/142189-solved-query-datetimes/#findComment-745037 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.