Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to calculate the total number of days using sql
My requirement is I have posted date and a current date using these two dates i want to calculate the total number of days
Posted
Updated 19-Jun-12 21:04pm
v2
Comments
bhagirathimfs 20-Jun-12 3:05am    
I think u want the difference between the current date and posted date.

SQL
declare 
@startdate date,
@enddate date
set @enddate='20120901'--yyyymmdd'
set @startdate='20120316'--'yyyymmdd'
select @startdate ,@enddate 
,DATEDIFF(YY,@startdate,@enddate)'int.age in years'
,DATEDIFF(DD,@startdate,@enddate )'int.age in days'
,DATEDIFF(mm,@startdate,@enddate)'int.age in months'
 
Share this answer
 
 
Share this answer
 
Comments
Prasad_Kulkarni 19-Jul-12 4:48am    
My 5!
HI,
Check this
SQL
declare @t1 nvarchar(10)
set @t1 ='1/1/2010'
declare @t2 nvarchar(10)
set @t2 ='1/3/2010'

select datediff(DAY,convert(datetime, convert(char(10), @t1,110)),convert(datetime, convert(char(10),@t2, 110)))


Best Regards
M.Mitwalli
 
Share this answer
 
Use DateDiff to find the date difference in sql.
This link may help you to use DateDiff
DateDiff[^]
 
Share this answer
 
Comments
Tim Corey 26-Jun-12 12:58pm    
DateDiff is what you want to use but the link you provided is for Access, not SQL.

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