Search code examples
sqlitecomparisonstrftime

Comparison of strftime() return value does not work


The sqlite alias is not working properly

SELECT *,strftime('%s', `created_at`) AS `created_at_timestamp` FROM `sales` WHERE `created_at_timestamp` >= 1607966400 ORDER BY `created_at` DESC

This gives results even though the results should be 0 enter image description here


Solution

  • The documentation says:

    An INTEGER or REAL value is less than any TEXT or BLOB value.

    The return value of strftime() is a string. If you want to compare it against a number, convert it into a number first.