[thelist] why doth i hate css? let me count the ways.

Joshua Olson joshua at waetech.com
Sat Oct 11 22:36:34 CDT 2003


I owe:

<tip type="SQL" author="Joshua Olson">
This method will return the 3rd Wednesday, 2nd Tuesday, or whater.  The nth
Day of the week for a given month.  Note: it uses the change_datepart that I
offered up earlier.

@week is a number between 1 and 5.
@dow is a number between 1 and 7.
@sdate is a date within the month you are looking at.

CREATE FUNCTION nth_dow_of_month (@week int, @dow int, @sdate datetime)
RETURNS datetime AS
BEGIN
  DECLARE @tdate datetime
  Set @tdate = dbo.change_datepart('dd', 1, @sdate)
  IF @dow >= DatePart(dw, @tdate)
    BEGIN
      Set @tdate = DateAdd(d, @dow - DatePart(dw, @tdate), @tdate)
    END
    ELSE
    BEGIN
      Set @tdate = DateAdd(d, @dow - DatePart(dw, @tdate) + 7, @tdate)
    END

  RETURN DateAdd(ww, @week - 1, @tdate)
END
</tip>

<><><><><><><><><><>
Joshua Olson
Web Application Engineer
WAE Tech Inc.
http://www.waetech.com
706.210.0168



More information about the thelist mailing list