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!

Correct format for 2000/01/01 13:12:45

Status
Not open for further replies.
Jun 27, 2001
837
0
0
US
Am trying to come up with correct format for date to show
yyyymmddhhmmss. Tried to convert to char with 112 and 120. Any help appreciated
 
Code:
SELECT CONVERT(varchar(20), getdate(), 120)

You can use the Replace function to get rid of spaces, - and : if you need to. --James
 
select CONVERT(varchar, myDate, 120) as TheDate
etc

Is this what you meant?
HTH,
Graham
 
Close, however I just need the numbers
no dashes or spaces.
I tried
declare @date datetime
declare @vdate char(10)
set @date = getdate()
set @vdate = convert(char(18), @date, 112)
select @vdate
and you get 20030217, no hhmmss, that's the part i am looking for
 
This will work:

Code:
SELECT CONVERT(varchar(20), getdate(), 112) + Replace(CONVERT(varchar(20), getdate(), 108), ':', '')
--James
 
That's because your CONVERT is using 112, which is yyyymmdd - the time was never there. Try using 120, and see BOL CONVERT for the various formats.
 
timscronin,

When you give someone a virtual "pat on the back," make sure you let them know who is the recipient. From your comment, I can't determine who gave you the answer you used. If you haven't read the FAQs listed below, I recommend that you do. If you want to get the best answer for your question read faq183-874 and thread183-468158.
Terry L. Broadbent - DBA
SQL Server Page:
 
HOW DO YOU CONVERT, FORMAT OR GET IT TO DISPLAY JUST 01/01/03 INSTEAD OF THAT LONG DATE AND TIME. lonniejohnson@prodev.com
ProDev, MS Access Applications B-) ,
May God blow your mind with His Glory in 2003.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top