1

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?

2 Answers 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

2
  • Yup, "What database I'm using?" this helped me. THANKS! I was using wrong syntax.
    – lilu
    Nov 6, 2012 at 23:12
  • @lilu i know its a small thing, but I too asked something very similar..maybe u didnt see mine? Nov 7, 2012 at 0:45
0

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?

2
  • I already tried this and it gives me the same error : invalid indentifier
    – lilu
    Nov 6, 2012 at 19:33
  • @lilu can you execute this: SELECT DATEDIFF(day,'1/1/2011','1/1/2012') This worked for me.. I get 365 Nov 6, 2012 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.