1. Where year (A) = year (B) and month (A) = month (B) and day (A) = Day (B)
Actually, it can be implemented in a more concise way.
Where datediff (day, a, B) = 0
Similarly, the method to compare whether A and B are in the same month of the same year is:
Where datediff (month, a, B) = 0
2. In the date function of the ms SQL Server, "0" can be used to replace the date, "0" indicates the date is.
3. Remove the time, minute, and second information returned by the getdate () function.
Dateadd (day, datediff (day, 0, getdate (), 0)
4. display the time returned by the getdate () function as the day of the week
Select datename (weekday, getdate ())
The result is related to the value of @ datefirst.
5. The default datetime format of the Chinese version of SQL Server is yyyy-mm-dd thh: mm: Ss. Mmm. If we need different date formats such as 2005/10/27, 2005-10-27,
You can use the following function:
Select convert (varchar (10), time, 120)
Here, 120 can be replaced by a value between 101 and 114 (108 obtains the time ).
Of course, you must change varchar (10) To varchar (12) in several cases to display it completely.
Below are several common values:
120 results:
102 results: 2005.10.25
111 results:
101 results:
112 results: 20051027