Aug 26, 2013

Sql script to know or set first day of week in sql server


We can get the first day of any week by following sql query:

SELECT @@DATEFIRST AS FirstDay

Or

SELECT
    CASE @@DATEFIRST
         WHEN 1 THEN 'Monday'
         WHEN 2 THEN 'Tuesday'
         WHEN 3 THEN 'Wednesday'
         WHEN 4 THEN 'Thursday'
         WHEN 5 THEN 'Friday'
         WHEN 6 THEN 'Saturday'
         WHEN 7 THEN 'Sunday'
    END AS FirstDay

Default value of first day of week varies according to language. For us_english is 7 that is Sunday.

We can set first day of week by following sql script:

SET DATEFIRST 5

No comments:

Post a Comment