.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Imran Ghani
Sohaib Khalid

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Difference between two dates

Posted By: priya     Posted Date: June 30, 2010    Points:2   Category :C#

I want to count the no of days between two dates. Can any one Give me syntax for this.

I am using asp.net and C#


Author: Suresh          Accepted Answer   
Posted Date: June 30, 2010     Points: 10   

Hello Priya,
Kindly try below query model,

Declare @t table
id int identity(1,1),
name nvarchar(50),
dates datetime
Insert into @t
Select 'AA',getdate()
Union All
Select 'bb',getdate()+1
Union All
Select 'cc',getdate()+2
Union All
Select 'dd',getdate()+4

Select * from @t
Select getdate()
Select getdate()+2
Select count(*) counts from @t where dates between getdate() and getdate()+2

Let me know that, do you need any further clariffication.
If its correct mark as answer

Author: Kirtan          Accepted Answer   
Posted Date: June 30, 2010     Points: 10   

DateTime dt1 = DateTime.Now;
DateTime dt2 = DateTime.Now.AddDays(30);

TimeSpan t1 = dt2.Subtract(dt1);

Response.Write("Date Time Diffrence in Days :" + t1.Days);

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend