Click here to Skip to main content
14,735,364 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.
__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?

You Can Find the diffrence even in nanosecond format!!
Use DATEDIFF Function.
difference between two dates get Result in days
select datediff(d, '2012-10-05' , '2012-11-21')

Happy Coding!
you can try something like below :

SELECT DATEDIFF(DAY, convert(datetime,'5.10.2012',104),  convert(datetime,'21.11.2012',104)) as Difference
Try this Query....

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


SELECT DATEDIFF(dd,'24 March 1964','24 March 2001')

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