Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Variable - YYYYMMDD

Status
Not open for further replies.

jconway

Programmer
Dec 14, 2005
50
0
0
I'm trying to create today's date as a variable in the format YYYYMMDD. In my expression I'm getting errors with everything I try. I've tried:

cast(convert(varchar(12), getdate(), 112) as int)

select cast(convert(varchar(12), getdate(), 112) as int)

select FullDate
from dim_Date
where DateKey = cast(convert(varchar(12), getdate(), 112) as int)


Can anyone tell me what I'm missing here? It may be quite obvious which is why I'm asking for advice.

Thanks!
 
SOLUTION:

(DT_STR,4,1253)YEAR(GETDATE()) + RIGHT("0" + (DT_STR,2,1253)MONTH(GETDATE()),2) + RIGHT("0" + (DT_STR,2,1253)DAY(GETDATE()),2)
 
How about
Code:
CONVERT(CHAR(8), GETDATE(), 112)
?

soi la, soi carré
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top