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