Jump to content

Question about a time restricted query.


Ninjakreborn

Recommended Posts

SELECT title,dateFrom From tbl_event WHERE (`dateFrom` = CURDATE()) OR (`dateFrom` > DATE_ADD(CURDATE(), INTERVAL -2 DAY)AND `dateFrom` < CURDATE()) order by dateFrom asc  LIMIT 0,4

 

I just want to see if there were any results today, or yesterday. That's pretty much it. The above code seems to be off, any advice is appreciated.

Link to comment
https://forums.phpfreaks.com/topic/268216-question-about-a-time-restricted-query/
Share on other sites

No need to have an OR clause to pull records from today OR yesterday. Just create a value for the records starting yesterday and do a greater than comparison.

 

However, your code is going TWO days back. So, you are getting everything from today, yesterday and the prior day.

 

This should work

SELECT title, date

From From tbl_event

WHERE `dateFrom` >=  DATE_SUB(CURDATE(), INTERVAL 1 DAY)

 

This will get all the values from today and yesterday

Archived

This topic is now archived and is closed to further replies.

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