• Note that the output of your function depends on the value of @@DATEFIRST:

    declare @DateFirst int

    select @DateFirst = @@DATEFIRST

    set datefirst 1

    select dbo.Monday('2006-02-13','2006-02-20')  --Returns 2

    set datefirst 7

    select dbo.Monday('2006-02-13','2006-02-20')  -- Returns 1 (incorrect)

    set datefirst @DateFirst -- Resets @@DATEFIRST to original value