Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in database i have two column from and to date.

from date 5.10.2012
to date 21.11.2012

for that i want to get the difference between two dates.for that i how to write the query in sql server.
Posted
Comments
__TR__ 21-Nov-12 6:27am    
Take a look at DATEDIFF[^] (Transact-SQL)
Prasad Guduri 27-Nov-12 1:25am    
It varies based on your requirement. Th difference in what ? Days ? Minutes ? Hours?

difference between two dates get Result in days
SQL
select datediff(d, '2012-10-05' , '2012-11-21')


Happy Coding!
:)
 
Share this answer
 
Try this Query....

SQL
select datediff(mi, '2012-10-05 15:29:55.090' , '2012-11-21 15:30:09.153')



OR

SQL
SELECT DATEDIFF(dd,'24 March 1964','24 March 2001')
 
Share this answer
 
v4
you can try something like below :

SQL
SELECT DATEDIFF(DAY, convert(datetime,'5.10.2012',104),  convert(datetime,'21.11.2012',104)) as Difference
 
Share this answer
 
v2
You Can Find the diffrence even in nanosecond format!!
Use DATEDIFF Function.
 
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