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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GETDATE() format for hhmmssmm 1

Status
Not open for further replies.

scotttom

IS-IT--Management
Mar 5, 2002
143
US
I'm looking for the best way to get a time to a hhmmssmm format.

I've got the following....

Code:
replace(Convert (varchar(8),GetDate(), 108),':',') + '00'
But unfortunately I need the milliseconds and not just "00" at the end.

Anybody know the best way to get there?

Thanks in advance!

Best,

Scott

 
Try using style 121 instead of 108. 108 does not include milliseconds.

Here's a version that includes 3 digits for milliseconds:

Code:
Select Replace(Replace(Right(Convert(varchar(30), GetDate(), 121), 12), ':', '), '.',')


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks gmastros!

Code:
LEFT(Replace(Replace(RIGHT(Convert(varchar(30), GetDate(), 121), 12), ':', '), '.','),8)

got me what I need.

Thanks for pointing me in the right direction!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top