I am using SQL Server with t-Sql
I have the following code that checks to see if a date falls on a weekend
and if it does, it will iterate until the day falls on a weekday
Declare @ProDate as Date
set @ProDate = '08/05/12'
WHILE (DATEPART(DW, @ProDate) = 1 OR DATEPART(DW, @ProDate) = 7 )
BEGIN
set @ProDate = DATEADD(day, 1, @ProDate)
END
select @ProDate
The code seems to work. Wondering if I missed anything or if there is a better way to handle this.
This code will work. It is almost identical to code that we use in a heavily used function.
The only suggestion that I might have is do you need to integrate a Holiday check? We have a Holiday table to store dates that need to be skipped as well.