DateDiff Function

懵懂的女人 提交于 2019-12-02 07:09:14

问题


I am trying some examples for DateDiff Function

SELECT DATEDIFF(day,'2008-06-05','2008-08-05') AS DiffDate 

This statement gives me an error From keyword not found where expected. Why do I get this error and how can I solve it? Also, when I try this :

SELECT DATEDIFF(day,datebegin,datestop) 
From table; 

I get this error "datediff" invalid identifier. How can I get day difference?


回答1:


What database are you using?

A google search gave me this:

http://www.mssqltips.com/sqlservertip/2508/sql-server-datediff-example/

DAY SELECT DATEDIFF(DD,'09/23/2011 15:00:00','08/02/2011 14:00:00')

where 'DD' is used as opposed to 'days'.

Try answering these question:

What database I'm using?

Is the database case sensitive? This might be the error occurring with the datediff as oppose to DATEDIFF




回答2:


try SELECT DATEDIFF(dd,datebegin,datestop) from table

I think 'day' also works, I was able to execute:

SELECT DATEDIFF(day,'1/1/2011','1/1/2012') 

So Im not sure what you're doing wrong.. What version of SQL Server are you using?



来源:https://stackoverflow.com/questions/13257968/datediff-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!