Reputation: 65
I'm trying to use DATEDIFF function inside an IF clause as the following:
select if('2006-04-01',DATEDIFF('2006-04-01','2007-04-01'),'y');
But the result I get is BLOB
!!
How Can I use DATEDIFF
within an IF
statement and get a meaningful result.
Thank you all
Upvotes: 1
Views: 11759
Reputation: 23123
From what I understand, the if
statement works as follows:
select if(expr, true, false)
Also, DATEDIFF
returns an int not a date, so you would want to take the return value of DATADIFF
and compare it against a known number of days or 0 perhaps, or the return of another DATEDIFF
operation.
select if(datediff(date1, date2) >= 20, 'true statement', 'false statement')
Upvotes: 0
Reputation: 5290
You may misunderstood the if function
select if( datediff('2006-04-01','2012-01-01') > 0, 1, 0 );
works very well
The result of datediff in my case mysql 5.5.24 is an integer.
Upvotes: 1