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!

format 3/1/2004 to 20040301 (yyyymmdd)? 1

Status
Not open for further replies.

Dan01

Programmer
Jun 14, 2001
439
0
0
US
Is there a function I can use in a TRANSACT-SQL statement to make this date conversion? Thanks, Dan.
 
select convert(varchar, GETDATE(), 112) will format the date in the way you want, for example
 
Try this:
Code:
declare @mydate datetime

set @mydate = '03/01/2004'

select convert(char(8),@mydate,112)
You only need the last line of the code if you already have a date field. Just swap @mydate with your field.

~Brian
 
Try using the following:
Code:
select replace(convert(char(10), getdate(), 121), '-', '')
CONVERT is changing the date to the format yyyy-mm-dd hh:mi:ss.mmm(24h), and only returning the first 10 characters. REPLACE is removing the '-' only leaving you with the format you are looking for.

Dan.
 
Thanks Brian and Dan! Dan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top