72、时间差函数
sqlserver | PostgreSQL | mysql | |
---|---|---|---|
Years | DATEDIFF(yy, start, end) | DATE_PART(‘year’, end) - DATE_PART(‘year’, start) | TIMESTAMPDIFF(YEAR ,start,end) |
Months | DATEDIFF(mm, start, end) | years_diff * 12 + (DATE_PART(‘month’, end) - DATE_PART(‘month’, start)) | TIMESTAMPDIFF(MONTH,start,end) |
Days | DATEDIFF(dd, start, end) | DATE_PART(‘day’, end - start) | TIMESTAMPDIFF(DAY ,start,end) |
Weeks | DATEDIFF(wk, start, end) | TRUNC(DATE_PART(‘day’, end - start)/7) | TIMESTAMPDIFF(DAY ,start,end)/7 |
Hours | DATEDIFF(hh, start, end) | days_diff * 24 + DATE_PART(‘hour’, end - start ) | TIMESTAMPDIFF(HOUR ,start,end) |
Minutes | DATEDIFF(mi, start, end) | hours_diff * 60 + DATE_PART(‘minute’, end - start ) | TIMESTAMPDIFF(MINUTE ,start,end) |
Seconds | DATEDIFF(ss, start, end) | minutes_diff * 60 + DATE_PART(‘minute’, end - start ) | TIMESTAMPDIFF(SECOND ,start,end) |