How to compare now to a timestamp in Mysql, when valid_date is greater than now 1, else 0?
I only have data of valid_date
, I need data of is_valid
, thanks so much for any advice.
valid_date is_valid
1675739460 0
1680837060 1
1678190564 1
1686365124 1
2
Answers
You should be able to
SELECT
a boolean result by comparing theUNIX_TIMESTAMP()
withvalid_date
.To compare a timestamp to the current time in MySQL, you can use the NOW() function, which returns the current date and time.
To create a condition where valid_date is greater than NOW() – INTERVAL 1 DAY, you can use the following query:
You can adjust the time interval as needed by changing the value passed to INTERVAL.