For every row in the database I have a field that contains a timestamp of when that row has been inserted into the database. The date’s format is “YYYY-MM-DD HH-MM-SS”.
This is because I want the new rows to appear with a different style in the website. For example, I want all the rows inserted in the last 24 hours to appear with a different background color. I wrote this code but it counts every table row as new:
The idea is to convert both dates to a UNIX timestamp and then check if their different is less than 24 hours. This would mean that the row is new. Can you spot the mistake?
SELECT something
, somethingelse
, dateofinsert
, CASE WHEN dateofinsert >=
CURRENT_TIMESTAMP - INTERVAL 24 HOUR
THEN 1
ELSE 0 END AS new_in_last_24_hours
SELECT
FROM daTable
SELECT name
, date
, dateofinsert
, CASE WHEN dateofinsert >=
CURRENT_TIMESTAMP - INTERVAL 24 HOUR
THEN 1
ELSE 0 END AS new_in_last_24_hours
SELECT
FROM appuntamenti