Jump to content

Between date columns


sw9

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.