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

VulpesRank #55 · 29.2K reputationPosted Jun 17, 2011, 3:29 AM EDT
Dorababu MekaRank #457 · 5.5K reputationPosted Jun 17, 2011, 3:32 AM EDT
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();
}
Anthony Clarke99 reputationPosted Jun 17, 2011, 4:25 AM EDT
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 MekaRank #457 · 5.5K reputationPosted Jun 17, 2011, 4:47 AM EDT