1

我正在尝试DateDiff 函数的一些示例

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

该语句给了我一个错误 From keyword not found where expected 。为什么我会收到此错误,我该如何解决?另外,当我尝试这个时:

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

我得到这个错误"datediff" invalid identifier。我怎样才能获得日差?

4

2 回答 2

0

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

于 2012-11-06T19:35:24.467 回答
0

尝试SELECT DATEDIFF(dd,datebegin,datestop) from table

我认为“一天”也有效,我能够执行:

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

所以我不确定你做错了什么。你使用的是什么版本的 SQL Server?

于 2012-11-06T19:30:19.030 回答