sw9 Posted February 26, 2010 Share Posted February 26, 2010 hi guys, i've read up on the mysql date functions, but i'm not quite clear on how to do this query. I have a current datestamp called 'mydate' in 'Y-m-d H:i:s' format. Then I have a mySQL table that has a 'startdate' and 'enddate' columns. I need to select the record where 'mydate' is between the startdate and enddate columns. For example, let's say 'mydate' = '2010-02-25 09:36:05'. Then in mytable I have a record which has a startdate field set at '2010-02-25 09:00:00' and it has an enddate field set at '2010-02-25 10:00:00'. I want that record to get retrieved because my date is between those two fields. I know how to do betweens on a single column, but I can't figure out how to do it like I need. any help? Quote Link to comment https://forums.phpfreaks.com/topic/193477-between-date-columns/ Share on other sites More sharing options...
DavidAM Posted February 26, 2010 Share Posted February 26, 2010 Try this: WHERE '2010-02-25 09:36:05' BETWEEN startdate AND enddate Quote Link to comment https://forums.phpfreaks.com/topic/193477-between-date-columns/#findComment-1018582 Share on other sites More sharing options...
sw9 Posted February 26, 2010 Author Share Posted February 26, 2010 Duh. Sorry, I was not doing this right because I wasn't nesting my where clause correctly. All in all it just came to: select DISTINCT cs.nid from content_type_showing cs WHERE cs.field_channel_value = '11' AND ('$mytime' BETWEEN cs.field_showing_airtime_value AND cs.field_showing_airtime_value2 OR cs.field_showing_airtime_value >= '$mytime') order by cs.field_showing_airtime_value LIMIT 6 Quote Link to comment https://forums.phpfreaks.com/topic/193477-between-date-columns/#findComment-1018607 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.