There is an INT field which I store timestamps in table.
I am trying to select rows 1 week before this timestamp
WHERE last_loc_date > DATE(NOW()) - INTERVAL 1 WEEK
Doesn't work. Any idea?
There is an INT field which I store timestamps in table.
I am trying to select rows 1 week before this timestamp
WHERE last_loc_date > DATE(NOW()) - INTERVAL 1 WEEK
Doesn't work. Any idea?
You could use unix_timestamp
to calculate second argument:
WHERE last_loc_date > unix_timestamp(DATE(NOW()) - INTERVAL 1 WEEK)
Please avoid using FROM_UNIXTIME(last_loc_date) > DATE(NOW()) - INTERVAL 1 WEEK
. This condition is not SARGable unless you use function-based index.
Don't use DATE(now()) if you want respect the strictly one week
WHERE last_loc_date > unix_timestamp(NOW() - INTERVAL 1 WEEK)