Reputation: 6099
I need to check whether my date
field is in the future using MySQL and if so, add an extra column. It's important that I do not want to make this part of my where clause as I want to return rows where the date
field is not in the future.
For example:
select
dateIsInFuture = 'true' if date > now()
I know the above is not valid syntax but I need to know how to write that in a valid SQL statement.
Thanks
Upvotes: 0
Views: 304
Reputation: 2968
You can use if, but using this syntax:
SELECT IF(date > now(), 'true', 'false') as FutureFlag FROM YOUR_TABLE
Upvotes: 0
Reputation: 204756
select *, case when date_col > now()
then 'true'
else 'false'
end as dateIsInFututre
from your_table
Upvotes: 4