0

I need to calculate personnel's working age from PerBeginDate to PerEndDate fields. The format must be in y/m/d, such as 1/5/10 (1 year 5 months 10 days) or 0/0/30 (30 days).

Red Romanov
  • 454
  • 5
  • 11

1 Answers1

0

This is the closest solution I can think of

 CONCAT(IFNULL(YEAR(FROM_DAYS(DATEDIFF(PerEndDate,PerBeginDate))),0)," / ",
  MONTH(FROM_DAYS(DATEDIFF(ADDDATE(PerEndDate,INTERVAL 1 YEAR),PerBeginDate)))-1," / ",
  DAY(FROM_DAYS(DATEDIFF(ADDDATE(PerEndDate,INTERVAL 1 YEAR),PerBeginDate)))-1)

The INTERVAL 1 YEAR part is to prevent the DATEDIFF from showing 0.

Red Romanov
  • 454
  • 5
  • 11