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

           
       








Related examples in the same category

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