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

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

how do i get the number of days between two dates

Posted By: Ramesh     Posted Date: February 13, 2009    Points:2   Category :C#
Hello Friends,
How do i get the no of days between two given dates. In other ways how can i get the difference between two given dates,

for eg.

First Date - 1/1/2009

Last Date - 23/1/2009

result would be 22 days.

How can i achieve using C#.


Author: susant             
Posted Date: February 14, 2009     Points: 5   

Hi Ramesh... just check this...

DateTime dt1,dt2;
dt1 =Convert.ToDateTime(TextBox1.Text);
dt2 =Convert.ToDateTime(TextBox2.Text);

string diff = ((TimeSpan)(dt2 - dt1)).Days.ToString();
TextBox3.Text = diff.ToString();

I think it may help u..


Author: Athira Sreejith             
Posted Date: February 24, 2009     Points: 5   


Just try like this..

TimeSpan ts;
DateTime LoginTime = DateTime.Parse(1/1/2009);
DateTime LogoutTime = DateTime.Parse( 23/1/2009);
LoginTime = Convert.ToDateTime(LTimes[0].ToString());
LogoutTime = Convert.ToDateTime(LTimes[1].ToString());
ts = LogoutTime - LoginTime;
ts = new TimeSpan(LogoutTime.Ticks - LoginTime.Ticks);
TotalTime = ts.Days.ToString();

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