Jump to content

Query trouble - working with dates & intervals


Recommended Posts

Hello,

 

I've got a small chunk of code that is refusing to behave and I'm hoping a fresh pair of eyes will help

 

right now I have

 

SELECT s.id AS msg_id, UNIX_TIMESTAMP(s.msg_date) AS msg_date, u.id AS userid, loc.name AS loc_name, l.id AS look_id
FROM bil_msg_sent AS s
JOIN bil_msg_look AS l ON (l.locid = s.locid)
JOIN bil_users AS u ON (u.id = s.userid)
JOIN bil_location AS loc ON (l.locid = loc.id)
WHERE s.msg_date BETWEEN l.look_date - INTERVAL 1 hour AND l.look_date + INTERVAL 1 hour
AND l.id = '3'
AND s.active = 1
AND l.active = 1
ORDER BY s.msg_date ASC

 

when I take out

WHERE s.msg_date BETWEEN l.look_date - INTERVAL 1 hour AND l.look_date + INTERVAL 1 hour

 

I get 5 results,

 

when I put it in I get none,

 

I've gone in and manually matched the dates in the s.msg_date column to that of l.look_date in those 5 entries though I'm still getting nada for results

 

any fresh perspectives?

 

head is beginning to get sore and think I might need to replace this keyboard  ::)

I suppose I should have mentioned that I've already torn this query apart and started fresh piece by piece,

 

everything works property until I add in the the WHERE with the Interval,

 

I have a similar query with the same where clause working in a different page...

 

suppose I'll get back to the proverbial drawing board

funny,

 

I tried writing and re-writing this query a dozen times and couldn't figure it out,

 

then I went back and checked the data itself....

 

I had missed setting one of the fields to active = 1 from active = null

 

;D

 

now where can I find a dunce cap?

 

 

also any reason why I can't mark this as solved?

have something to do with the forum upgrade yesterday?

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.