0

Hi, I have what I hope will be a quick and easy question.

I am trying to select all records from a table called prod_enroll that were last updated on yesterday's date

This query works, but I was just wondering if there wouldn't be a more elegant way to accomplish this?

The last_update is a datetime field, but the time is irrelevant for this query.

$sql = "
  SELECT mem_id
  FROM prod_enroll
  WHERE date(last_update) > DATE_ADD(CURDATE(), INTERVAL -2 DAY) AND date(last_update) < CURDATE()
  AND rel_code = 'E'
";

Any suggestions would be greatly appreciated.

Thanks
Douglas

2
Contributors
2
Replies
7
Views
3 Years
Discussion Span
Last Post by showman13
1

Why not use:

WHERE DATE(last_update) = DATE_ADD(CURDATE(), INTERVAL -1 DAY)

Since you are only checking dates (and not times), no need for the between.

Votes + Comments
The simpler the better
0

Thank You Sir...

I would have sworn that I had tried that variation yesterday, but apparently on that I missed.

Was getting lost in trying to match the date only in a datetime field, and apparently overthinking it. Not unusual for me.

That worked just fine...

Thanks for your help.
Douglas

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.