I have a table like this:
// mytable +----+------------+ | id | date_time | +----+------------+ | 1 | 1464136759 | -- 5 days ago | 2 | 1464436759 | -- 2 days ago | 3 | 1464538248 | -- 6 hours ago +----+------------+ -- ^ these are based on current time which is 1464561158
I also have this query:
SELECT id, CASE DATE(FROM_UNIXTIME(date_time)) WHEN CURDATE() THEN 'today' WHEN CURDATE() - INTERVAL 1 DAY THEN 'yesterday' WHEN CURDATE() - INTERVAL 7 DAY THEN 'in last week' ELSE 'in last month or more' END range FROM mytable WHERE 1
And here is the current output:
+----+---------------+ | id | range | +----+---------------+ | 1 | in last month | | 2 | in last month | | 3 | yesterday | +----+---------------+
As you can see, my question selects all these unix-times errors. Why and how can I fix this?
Here's the expected result:
+----+--------------+ | id | range | +----+--------------+ | 1 | in last week | | 2 | yesterday | | 3 | today | +----+--------------+
source share