Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Sir I want to find diffrence of Days between 2 Dates.
I am using in .NET/in .aspx Page like ...
DateTime dtTime = Convert.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy"));
DateTime DtExp = Convert.ToDateTime("9/12/2011");
TimeSpan ttsD = dtTime.Subtract(DtExp); int Days = Convert.ToInt32(ttsD.TotalDays);

Similarly I want to find diffrence between 9/12/2011 and 9/14/2011 in SQL side directly
the resuld should 2; What will the code in SQL
Posted

1 solution

Use the below function
SQL
Syntax:
DATEDIFF ( datepart , startdate , enddate )
Eg:
SELECT DATEDIFF(day, '9/12/2011' ,GETDATE())
 
Share this answer
 
Comments
LebneizTech 14-Sep-11 9:14am    
Very Very Thanks,
Got Exact Solution

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