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?
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
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