Click here to Skip to main content
14,668,658 members
Rate this:
Please Sign up or sign in to vote.
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?

Rate this:
Please Sign up or sign in to vote.

Solution 4

You Can Find the diffrence even in nanosecond format!!
Use DATEDIFF Function.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

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


Happy Coding!
:)
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

you can try something like below :

SELECT DATEDIFF(DAY, convert(datetime,'5.10.2012',104),  convert(datetime,'21.11.2012',104)) as Difference
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

Try this Query....

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



OR

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

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100