I am trying to calculate age with the SQL statement below
round(datediff(now() - dateofbirth / 365))
gives the following error,
1582 – Incorrect parameter count in the call to native function ‘datediff’
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Problem :
datediffexpects two parameters likeDATEDIFF(expr1,expr2), as per the given question, there is only one parameter hence error.Solution : you have to use,
the
datediffreturnsexpression1 – expression2, so you dont have to do it by yourself 🙂 also make sure the parameters are date or date-and-time expressionsEDIT : Another error pointed out by @Jonathan Leffler,division is needed after the call to
DATEDIFF.