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' 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -