C# Calender Days

How to find out how many calender days are there between two dates in c#.net?

Questions by ushalakshmi   answers by ushalakshmi

Editorial / Best Answer

wyverex  

  • Member Since May-2008 | May 13th, 2008


DateTime t1 = new DateTime(2008, 5, 13);

DateTime t2 = new DateTime(2004, 2, 22);


TimeSpan span = (t1 > t2 ? t1 - t2 : t2 - t1);


Console.WriteLine(span.TotalDays);

Showing Answers 1 - 0 of 0 Answers

wyverex

  • May 13th, 2008
 

DateTime t1 = new DateTime(2008, 5, 13);

DateTime t2 = new DateTime(2004, 2, 22);


TimeSpan span = (t1 > t2 ? t1 - t2 : t2 - t1);


Console.WriteLine(span.TotalDays);

dhanu_mitra

  • Dec 31st, 2008
 

public void DateDiff()
{
     DateTime
startDate = DateTime.Parse("11/12/2008");

     DateTime endDate = DateTime.Parse("11/12/2009");

     if (endDate > startDate)

     {

          TimeSpan span = endDate.Subtract(startDate);           Console.WriteLine(span);

      }

}

ngobeseb

  • Nov 4th, 2009
 

Here is the better answer:

DateTime fDate = DateTime.Now;

int thisDay = fDate.DayOfYear; //if today's date is 31/12/2008, thisDay will be 365 and if today's date is 01/01/2009, thisDay will be 1.

Therefore, you can use DayOfYear propery to get the day number in a year.


  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions