SQL Server/T-SQL/Date Timezone/Day

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

Day(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>



DAY: return the day portion of a date as an integer

2> -- DAY: return the day portion of a date as an integer.
3>
4>
5> SELECT DAY("24 March 1964")
6> GO
-----------
         24
(1 rows affected)



select DAY("2002-09-30")

 

2> select DAY("2002-09-30")
3> GO
-----------
         30
(1 rows affected)
1>