Here is my query to find out age from the DOB column :
date_format (current_timestamp, '%Y_%m_%d') - date_format (c.memberdob, '%Y_%m_%d') as age
I am getting following error:
SYNTAX_ERROR: line 4:47: ‘-‘ cannot be applied to varchar, varchar
Appreciate your help!
Advertisement
Answer
You should be able to solve this using function DATE_DIFF(). From the documentation:
date_diff(unit, timestamp1, timestamp2)→bigintReturns
timestamp2 - timestamp1expressed in terms of unit.
Try:
DATE_DIFF('year', c.memberdob, current_timestamp) as age