I have a VARCHAR field completion_date that contains a timestamp date (ex 1319193919). Is it possible to run a query on such a field that compares it with NOW() ? I’m trying:
SELECT * FROM (`surveys`) WHERE `active` = '1' AND `archived` = '0' AND `completion_date` > 'NOW()'
But the results are not really what I’m expecting, is this cause of the VARCHAR? If so, what kind of date field am I better off using? The data must remain a Linux timestamp.
Convert
NOW()to a timestamp usingUNIX_TIMESTAMP()Also, remove the quotes you had around
'NOW()'N.B. In case you need it, the inverse of this function is
FROM_UNIXTIME()to convert a timestamp into the default MySQLDATETIMEformat.As mentioned in comments below, if you have the ability to make the change, it is recommended to use a real
DATETIMEtype instead ofVARCHAR()for this data.