SQL Server - To calculate total number of days using sql

Asked By abinav shankar on 20-Jun-12 03:03 AM
Hi
Chintan Vaghela replied to abinav shankar on 20-Jun-12 03:18 AM

Hi Frndz,

 

Functionality:  Get two date difference in Day in Sql server

 

Use DateDiff Function

 

Logic   :

 

 

 

Declare @PassDate as Varchar(10) = '06/14/2012' -- MM/dd/yyyy

 

Select DATEDIFF(DAY,CAST('06/14/2012' as DateTime), GETDATE()) as DifferDay

 

Hope this helpful!

Thanks

 

 

 

S K replied to abinav shankar on 20-Jun-12 03:36 AM
Simply get no. of days as follows 

SELECT DATEDIFF(dd,"24 March 1964","24 March 2001") 
so in you query you can put 

SELECT DATEDIFF(dd,CurrentDate,PostedDate)  As NoOfDays From tblname

hope this helps you
TSN ... replied to abinav shankar on 20-Jun-12 08:24 AM

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

you can get the difference in the Days ... by using above