Click here to Skip to main content
16,018,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friend
i want to convert to date time to minute second and millisecond and my problem is i want to convert to date time like

2013-06-05 15:45:40.000

and my query is
SELECT CONVERT(VARCHAR(8),GETDATE(),108) AS HourMinuteSecond
and output is
15:45:40

but i want to 154540 how to it possible plz help me
Posted
Updated 5-Jun-13 0:21am
v2

SQL
DECLARE @SAMPLEDATE VARCHAR(10)
DECLARE @FORMATTEDTIME VARCHAR(10)

SET @SAMPLEDATE = CONVERT(VARCHAR(8),GETDATE(),108)
SET @FORMATTEDTIME =   REPLACE(@SAMPLEDATE ,':','');

PRINT @FORMATTEDTIME 
 
Share this answer
 
Comments
Maciej Los 5-Jun-13 6:28am    
Good work ;)
+5
Zafar Sultan 5-Jun-13 6:33am    
Thanks.
[no name] 5-Jun-13 6:40am    
Awesome :)
Zafar Sultan 5-Jun-13 7:03am    
Thank you.
Use this:
SQL
SELECT REPLACE(CONVERT(VARCHAR(8),GETDATE(),108),':','') AS HMS


More about: REPLACE (T-SQL)[^]
 
Share this answer
 
Use Replace Function like below

SQL
SELECT replace(CONVERT(VARCHAR(8),GETDATE(),108),':','') AS HourMinuteSecond
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900