.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

SQL Script to Find Last Day of the Month

by jason10. July 2006 23:42

This Microsoft SQL script figures out what the last day of the month is (28, 30, or 31) so that you don't have to recite the "30 days has September, April, May, and November..." poem or do the "knuckle trick."

DECLARE @Date DATETIME
SET @Date = '1/1/2006'
SELECT DAY(DATEADD(d, -DAY(DATEADD(m,1,@Date)),DATEADD(m,1,@Date))) AS LastDayOfMonth

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.