Hi,
Im try to caluclate days from two datetimepickers
datetimepicker 1 = startdate
dattimepicker2 = end date
How would i go about calculating the days between the 2 datetimepicker but remove the saturdays and sundays from it?
Thanks in advance
Anthony
Loading
VulpesPosted Jun 17, 2011, 7:29 AM
Dorababu MekaPosted Jun 17, 2011, 8:47 AM
Anthony ClarkePosted Jun 17, 2011, 8:25 AM
Thankyou both for your quick response, they are both perfect but ill mark Vulpes as the correct answer as he was first to reply. Thats the only fair way i can think of. Thank you very much for your help though Dorababu M
Thanks alot Vulpes, your a star
Dorababu MekaPosted Jun 17, 2011, 7:32 AM
static void Main(string[] args)
{
DateTime d1 = Convert.ToDateTime("6/17/2011");
DateTime d2 = Convert.ToDateTime("6/22/2011");
TimeSpan s = d2.Subtract(d1);
DateTime nd;
int businessdayCounter = 0;
for (int i = 0; i < s.Days; i++)
{
nd = d1.AddDays(i);
if (nd.DayOfWeek == DayOfWeek.Saturday || nd.DayOfWeek
== DayOfWeek.Sunday)
{
// ignore
}
else
{
businessdayCounter++;
}
}
Console.Write(businessdayCounter);
Console.Read();
}