SQL Server/T-SQL/Date Timezone/Month

Материал из SQL эксперт
Перейти к: навигация, поиск

Month(Date) function

1> DECLARE @MonthChar VarChar(2), @DayChar VarChar(2), @DateOut Char(8)
2>
3> SET @MonthChar = CAST(MONTH(GETDATE()) AS VarChar(2))
4> SET @DayChar = CAST(DAY(GETDATE()) AS VarChar(2))
5>
6> -- Make sure month and day are two char long:
7> IF LEN(@MonthChar) = 1
8>   SET @MonthChar = "0"
9> IF LEN(@DayChar) = 1
10>   SET @DayChar = "0" + @DayChar
11>
12> -- Build date string:
13> SET @DateOut = @MonthChar + @DayChar + CAST(YEAR(GETDATE()) AS Char(4))
14>
15> SELECT @DateOut
16> GO
--------
10142006
(1 rows affected)
1>



MONTH: return the month portion of a date

12>
13> -- MONTH: return the month portion of a date.
14>
15> SELECT MONTH("24 March 1964")
16> GO
-----------
          3
(1 rows affected)



select MONTH("2002-09-30")

 

3> select MONTH("2002-09-30")
4> GO
-----------
          9
(1 rows affected)
1>