Home > SQL Server > Set First Day of the week

Set First Day of the week


First day represents the week beginning. It is more often use to set the business day of the week. By setting the first day of the week as per the business needs, you will get different result from date functions. In SQL Server, first day of the week is Sunday by default.

Day numbers in SQL Server

1- Monday

2 – Tuesday

3 – Wednesday

4- Thursday

5 – Friday

6 – Saturday

7 – Sunday

SQL Server (US English) default value is Sunday (7).

How to get first day value from server?

Execute this SQL Query : Select @@DateFirst

How to change Date First value in server?

Execute this SQL Query: Set DateFirst 5

5 is Friday. You can give any number between 1 and 7.

Implementation

–Set Thursday as the week start day

Set DateFirst 4

–Get Current day of this week 

Select GetDate() as Today, DatePart(dw, GetDate()) as DayOfWeek

This set command is very useful when we develop reports with data calculation.

Thanks for reading

 

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: