Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server
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 21-Nov-12 0:12am
Comments
__TR__ at 21-Nov-12 6:27am
   
Take a look at DATEDIFF[^] (Transact-SQL)
Prasad Guduri at 27-Nov-12 1:25am
   
It varies based on your requirement. Th difference in what ? Days ? Minutes ? Hours?
Rate this: bad
good
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!
Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

You Can Find the diffrence even in nanosecond format!!
Use DATEDIFF Function.
  Permalink  
Rate this: bad
good
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')
  Permalink  
v4
Rate this: bad
good
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
  Permalink  
v2

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

  Print Answers RSS
0 CPallini 375
1 Sergey Alexandrovich Kryukov 262
2 OriginalGriff 225
3 George Jonsson 114
4 Richard MacCutchan 110
0 OriginalGriff 6,344
1 Sergey Alexandrovich Kryukov 5,890
2 CPallini 5,175
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 25 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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