oracle 中计算两个日期的相差天数、月数、年数等等
如何计算两个日期的相差天数、月数、年数、小时数、分钟数、秒数
1、相差天数(两个日期相减)
2、相差小时数、分钟数、秒数
3、相差月数(months_between()函数)
4、相差年数(原先月数/12)
\
公司年龄计算方法:
规则:
语句:
SELECT I.PATIENT_ID,
TRUNC(SYSDATE) - TRUNC(I.BIRTH_DATE),
TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS'),
TO_CHAR(I.BIRTH_DATE, 'YYYY-MM-DD HH24:MI:SS') BIRTH_DATE,
(CASE
WHEN MONTHS_BETWEEN(TRUNC(SYSDATE), TRUNC(I.BIRTH_DATE)) / 12 >= 6 THEN
FLOOR(MONTHS_BETWEEN(TRUNC(SYSDATE), TRUNC(I.BIRTH_DATE)) / 12) || '岁'
WHEN MONTHS_BETWEEN(TRUNC(SYSDATE), TRUNC(I.BIRTH_DATE)) / 12 < 6 AND
MONTHS_BETWEEN(TRUNC(SYSDATE), TRUNC(I.BIRTH_DATE)) / 12 >= 1 THEN
FLOOR(MONTHS_BETWEEN(TRUNC(SYSDATE), TRUNC(I.BIRTH_DATE)) / 12) || '岁' ||
FLOOR((MONTHS_BETWEEN(TRUNC(SYSDATE), TRUNC(I.BIRTH_DATE)) -
FLOOR(MONTHS_BETWEEN(TRUNC(SYSDATE), TRUNC(I.BIRTH_DATE)) / 12) * 12)) || '月'
WHEN MONTHS_BETWEEN(TRUNC(SYSDATE), TRUNC(I.BIRTH_DATE)) / 12 < 1 AND
MONTHS_BETWEEN(TRUNC(SYSDATE), TRUNC(I.BIRTH_DATE)) >= 1 THEN
FLOOR(MONTHS_BETWEEN(TRUNC(SYSDATE), TRUNC(I.BIRTH_DATE))) || '月' ||
((TRUNC(SYSDATE) - TRUNC(I.BIRTH_DATE)) -
(TRUNC(SYSDATE, 'mm') - TRUNC(I.BIRTH_DATE, 'mm'))) || '天'
WHEN MONTHS_BETWEEN(TRUNC(SYSDATE), TRUNC(I.BIRTH_DATE)) < 1 THEN
(TRUNC(SYSDATE) - TRUNC(I.BIRTH_DATE)) || '天'
ELSE
'0' || '天'
END) AGE
FROM HIS.PIX_PATIENT_INFO I
评论