Month(Date) function : Month « Date Timezone « SQL Server / T-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>

           
       








Related examples in the same category

1.MONTH: return the month portion of a date
2.The DAY(), MONTH(), and YEAR() Functions
3.select MONTH('2002-09-30')