2

Is it possible to combine the functions year() and timestampdiff()? I have columns with persons, date of birth (dob) and dates of events, and I would like to know the age the person has at the first of July (01-07) in the year the event took place.

It would look like this: timestampdiff(year, dob, "year(event)-01-07")

Obviously, this does not work. Is there a way to calculate this?

Bingley
  • 21
  • 1
  • 4

1 Answers1

0

You can use concat to achieve this

select
   timestampdiff(year, dob, concat(year(event),'-',month(dob),'-',day(dob)))
from table_name;

or

select
   timestampdiff(year, dob, concat(year(event),'-',date_format(dob,'%m-%d')))
from table_name;
DEarTh
  • 975
  • 1
  • 7
  • 18