sql 找出两个日期之间的差异

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 找出两个日期之间的差异相关的知识,希望对你有一定的参考价值。


------------------------------------------Vertica----------------------------------------------------------------------------------------

select

age_in_months(Now(), '1988-06-21'),                                  --calculates completed period without current month
age_in_years(Now(), '1988-06-21'),                                   --calculates completed period without current month

datediff('month', '1988-06-21', Now()) as MonthsBetweenDates,        --includes current month in calculation
datediff('year', '1988-06-21', Now()) as YearsBetweenDates,          --includes current month in calculation  

months_between (Now(),'2017-01-01')                                  -- calculates months between two dates as a float

-----------------------------------------MySQL------------------------------------------------------------------------------------------------

select

period_diff(201712, 201707) as Past,      --months between now and a past date
period_diff(201806, 201712) as Future     --months between now and a future date

以上是关于sql 找出两个日期之间的差异的主要内容,如果未能解决你的问题,请参考以下文章

查找两个日期之间的差异 Oracle SQL

两个日期之间的oracle差异

sql查询计算不同列和相邻行的两个日期之间的差异

%b %d %Y 格式的两个日期之间的差异

如何使用 PHP 计算两个日期之间的差异?

Sql查询以查找两个给定日期之间的视图百分比差异