質問

How can I compute the difference between two dates, such that the query to be compatible with : MySql, H2 and 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

他のヒント

In SQL Server -

  datediff (day,startdate,enddate)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top