I am stuck with a particular Datepart Query
Declare @.day char(2)
Declare @.month char(2)
Declare @.year char(4)
Declare @.date char(8)
set @.day = (select DATEPART(day, GETDATE()))
set @.month = (select DATEPART(month, GETDATE()))
set @.year = (select DATEPART(year, GETDATE()))
set @.date = (select @.day + @.month + @.year)
The results for this query are displayed as follows
151 2004
I actually need to pad 1 with 01 and also repeat the same for the Day. So
if the date was 1st Jan 2004 then my current query would return
1 1 2004 (require 01012004)
How do I do this? Any help appreciated.
Thanks Sarahnot sure if this is the 'correct' way but I notice you are declaring the
variables as strings, so this should work:
declare @.day char(8)
set @.day = (select DATEPART(month, GETDATE()))
if len(@.day) < 2
set @.day = '0' + @.day
Select @.day
Cheers,
James Goodman MCSE, MCDBA
http://www.angelfire.com/sports/f1pictures
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment