.NET Script to Find Work Week Start and End

by jason13. July 2006 00:50

If you need to find the Monday of a given week or a Friday of a given week, this is the solution for you:

private DateTime WorkWeekStart(DateTime date)
{
DateTime result = date.AddDays(-((int)date.DayOfWeek)).AddDays(1); //Sunday + 1 = Monday
return result;
}
private DateTime WorkWeekStop(DateTime date)
{
DateTime result = date.AddDays(6 - ((int)date.DayOfWeek)).AddDays(-1); //Saturday - 1 = Friday
return result;
}

Tags: , ,

Development

SQL Script to Find Work Week Start and End

by jason13. July 2006 00:23

If you are looking for the Monday that starts a work week and/or the Friday that ends the work week, this is how you do it in SQL:

DECLARE @Today AS DATETIME
SET @Today = GETDATE()
SELECT DATEADD(wk, DATEDIFF(wk, 0, @Today), 0) AS Monday, DATEADD(wk, DATEDIFF(wk, 4, @Today), 4) AS Friday

Tags: , , ,

SQL

About

Jason Williams is a .NET developer in Lincoln, Nebraska.

The name "Centrolutions" came out of a long search for a domain name. The goal was to create a name that conveyed an ideology of writing software centered (Centr--) on a solution (--olutions) for a particular problem. In other words, it was the only name in a long list that wasn't already registered on the internet.

If you're looking for the products I have for sale, you should go here.