Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i want result like following on passing two date ;

01-11-2013 to 05-11-2015
     06-11-2013 to 11-11-2013 Coloumns
5                                                   6                                   Data
Posted
Updated 22-Dec-13 20:44pm
v5
Comments
Maciej Los 23-Dec-13 2:27am    
The difference between: 01-11-2013 and 05-11-2015 is 735 days.

Hello, consider to use DATEDIFF[^]

For example:
SQL
SELECT DATEDIFF(dd, CAST('2013-11-01' AS DATE), CAST('2013-11-05' AS DATE))


But this clause will return 4 for this dates pair not 5.
 
Share this answer
 
Comments
Maciej Los 23-Dec-13 2:13am    
Good job! A5!
I think OP wants to count each date including start date and end date. All you need to do is to add 1 ;)
skydger 23-Dec-13 6:05am    
Thanks :)
madhu.gone 23-Dec-13 2:14am    
but i am passing two dates dynmically
Maciej Los 23-Dec-13 2:57am    
And...
try this query :-
SELECT DATEDIFF(d, CAST('2013-11-01' AS datetime), CAST('2013-11-05' AS datetime)) ,DATEDIFF(d, CAST('2013-11-06' AS datetime), CAST('2013-11-12' AS datetime))


O/p:-
4 ,5
 
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