Agustin Fernandez wrote:
Hi all,
Im trying to achive the next task:
date1 = 10/25/2005;
date2 = 03/28/2006;
DiferenceInWeeks = date2 - date1; // Result must be showed in weeks
Can you help me writing this code?
Thx in advance!
DateTime date1 = new DateTime(2005, 10, 25);
DateTime date2 = new DateTime(2006, 3, 28);
TimeSpan difference = date2.Subtract(date1);
// Gets the number of seven-day periods in the time span:
int sevenDayPeriods = (int)Math.Ceiling(difference.TotalDays / 7);
If you want to know about differences in week numbers (i.e. week of the
year) then you have to mess around with the Calendar class.