How to get age in years,months and days using Oracle

前端 未结 4 1780
-上瘾入骨i
-上瘾入骨i 2020-12-17 03:53

I\'m trying to print for each person its age using this format :

E.g : 19 years , 8 months , 13 days.

I\'ve googled a lot and I\'ve noticed that there is a s

4条回答
  •  天涯浪人
    2020-12-17 04:32

    Syntax:

    SELECT 
      CONCAT(
        TIMESTAMPDIFF(YEAR, ?, NOW()),
        ' Years,',
        TIMESTAMPDIFF(MONTH, ?, NOW()) % 12,
        ' Months,',
        FLOOR(TIMESTAMPDIFF(DAY, ?, NOW()) % 30.4375),
        ' Days'
      ) AS age 
    FROM
      DUAL
    
    • Input: replace '?' with Date of Birth. For Example, '1994-07-08'
    • Output: This query will return age in 'X' Years 'Y' Months and 'Z' days.

提交回复
热议问题