Click here to Skip to main content
15,914,010 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi there, please help me with Sample code i can use to find the count of days between any two data strings. e.g. How acan i know the number of days between 1/12/2009 and 5/11/2010.

Thanks
Posted

Code as follows -
DateTime oldDate = new DateTime(2002,7,15);<br />
DateTime newDate = DateTime.Now;<br />
// Difference in days, hours, and minutes.<br />
TimeSpan ts = newDate - oldDate;<br />
// Difference in days.<br />
int differenceInDays = ts.Days;<br />
Console.WriteLine("Difference in days: {0} ", differenceInDays);




MSDN link here[^].
 
Share this answer
 
v2
Use this Code :

DateTime dt1 = new DateTime(2009, 12, 1);
DateTime dt2 = new DateTime(2010, 11, 5);
int nodays = dt2.Subtract(dt1).Days;


The nodays will hold the number of days between those dates.

Cheers.
:rose:
 
Share this answer
 

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