Skip to content

Instantly share code, notes, and snippets.

@alexohneander
Last active April 17, 2018 10:09
Show Gist options
  • Save alexohneander/0c4a0fd909ff051f3eaf0ff13dca06cb to your computer and use it in GitHub Desktop.
Save alexohneander/0c4a0fd909ff051f3eaf0ff13dca06cb to your computer and use it in GitHub Desktop.
Is the current day a weekday or a day of the weekend?
public Boolean weekend()
{
DateTime date = DateTime.Now;
if ((date.DayOfWeek == DayOfWeek.Saturday) || (date.DayOfWeek == DayOfWeek.Sunday))
{
Console.WriteLine("This is a weekend");
return true;
}
else
{
return false;
}
}
public Boolean EndofWorkingDay()
{
TimeSpan start = TimeSpan.Parse("08:00"); // 10 PM
TimeSpan end = TimeSpan.Parse("18:00"); // 2 AM
TimeSpan now = DateTime.Now.TimeOfDay;
if (start <= end)
{
// start and stop times are in the same day
if (now >= start && now <= end)
{
// current time is between start and stop
return false;
}
else
{
return true;
}
}
else
{
// start and stop times are in different days
if (now >= start || now <= end)
{
// current time is between start and stop
return false;
}
else
{
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment