sql - Error using the DATEDIFF syntax -
i'm trying find age of employees sample
database using code:
select empno, firstnme, lastname, job, birthdate, datediff(hour,birthdate,getdate())/8766 age employee job '%r';
but keep getting error :
"hour" not valid in context used.. sqlcode=-206, sqlstate=42703
this using ibm data studio 4.1.
assuming you're using db2
, doesn't support datediff
or getdate()
. instead, subtract dates , use current date
:
select empno, firstnme, lastname, job, birthdate, (current date - birthdate)/365.25 age employee job '%r'