简体   繁体   中英

Hibernate - difference between two dates

我如何计算两个日期之间的差异,以使查询与:MySql,H2和SqlServer兼容?

  • SQL Server - you can use DATEDIFF function that returns difference in specified DATEPART

SELECT DATEDIFF(dd,'1/20/2014,'1/22/2014')

http://technet.microsoft.com/en-us/library/ms189794.aspx


  • MySQL - DATEDIFF() just a little bit differently,

SELECT DATEDIFF('2008-11-30','2008-11-29') AS DiffDate

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_datediff


  • H2 - DATEDIFF

DATEDIFF('YEAR', T1.CREATED, T2.CREATED)

http://www.h2database.com/html/functions.html#datediff

在SQL Server中-

  datediff (day,startdate,enddate)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM