T-SQL DateTime FUNCTION

CREATE FUNCTION dbo.udf_DayOfWeek(@dtDate DATETIME)

RETURNS VARCHAR(10)

AS

BEGIN

DECLARE @rtDayofWeek VARCHAR(10)

DECLARE @weekDay INT

SET @weekDay=((DATEPART(dw,@dtDate)+@@DATEFIRST-7)%7)

SELECT @rtDayofWeek = CASE @weekDay

WHEN 1 THEN 'Pazar'

WHEN 2 THEN 'Pazartesi'

WHEN 3 THEN 'Salý'

WHEN 4 THEN 'Çarþamba'

WHEN 5 THEN 'Perþembe'

WHEN 6 THEN 'Cuma'

WHEN 0 THEN 'Cumartesi'

END

RETURN (@rtDayofWeek)

END

GO

SELECT dbo.udf_dayofweek(GETDATE())