Note: The following table in 0 is actually the date 1900-1-1
1.0 Points of the day
SELECT DATEADD (Day,DATEDIFF(Day,0,GETDATE()),0)
The above DateDiff (Day,0,getdate ()) means to calculate the number of days of the day and 1900-1-1, let's remember that this is N days, and then through the DateAdd calculated 1900-1-1 plus n days to reach the date of the day, time is 0.
2. The first day of the month
SELECT DATEADD (month,DATEDIFF(month,0,GETDATE()),0)
The principle is the same, but the calculation unit is changed from day to month.
3. The last day of the month
SELECT DATEADD (month,DATEDIFF(month,0,GETDATE())+1,0 )-1
The principle is to first calculate the first day of the next month, and then subtract the day.
4. Today is the day of the week
SELECT Datename (WEEKDAY,GETDATE()) -- input: Friday
5. Today is the first day of the week
SELECT DATEPART (DW,GETDATE()) -- The beginning of the week is Sunday, so 1 means Sunday, 7 means Saturday
But you can change this by the following language, such as the following modification the first day of the week for Monday:
SET 1
You can also view the values of the previous datefirst by saying the following:
SELECT @ @DATEFIRST
Some common uses of dates in MS SQL Server-Continuous updates