Click here to Skip to main content
15,895,843 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
Hi All,

when i try to diff between minute in sql server 2005, it i try this code working fine

SQL
select datediff(minute, '2011-01-02 12:00:00', '2011-01-02 12:30:00') as minutes


But This code showing Error, can you help me how to slove this one

SQL
SELECT DATEDIFF(minute, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000');


Thanks!
Posted
Comments
hypermellow 26-Aug-14 7:05am    
... could you update the question to include your error message please?
prasanna.raj 26-Aug-14 7:10am    
your are using SQL SERVER 2008 ?
prasanna.raj 26-Aug-14 7:09am    
Error! : Conversion failed when converting datetime from character string.

Try this:

SQL
SELECT DATEDIFF(minute, '2005-12-31T23:59:59.999', '2006-01-01T00:00:00.999');


Put a 'T' between date and time,and use just 3 digits for milliseconds
 
Share this answer
 
Comments
prasanna.raj 26-Aug-14 7:53am    
Thanks!...
Pikoh 26-Aug-14 8:09am    
You're welcome. BTW,you accepted solution 2,does that work to you?
prasanna.raj 26-Aug-14 8:13am    
why we reduce the ms any reason for that

59.9999999 to 59.999
Pikoh 26-Aug-14 8:18am    
That's by definition,i think it's in ISO 8601
prasanna.raj 26-Aug-14 8:23am    
oh ! thanks ...
Hi,

Try this...

SQL
SELECT DATEDIFF(minute, '2005-12-31 23:59:59.999', '2006-01-01 00:00:00.000');


Hope this will help you.


Cheers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900