Format output of time from a datetime field

I'm extracting data from sql server and need to output the data in a specific order and format.  The field I'm having trouble with is defined in sql server as a datetime field (8).  My extract requires the time to be formatted as a numeric 4 chars, as in military time with leading zeros, so 8:00 should appear as 0800   Here is my current statement:

Convert(varchar(10),dbo.calendar.start_time,108) as BegTime
which returns 08:00:00

I can't figure out if there is a style parameter that will give me what I need.
zknollAsked:
Who is Participating?
 
dhanushkadConnect With a Mentor Commented:

SELECT REPLACE(SUBSTRING(CONVERT(CHAR(8),GETDATE(),8) , 1,5),':','')
0
 
sm394Commented:
i am not sure aobut style param
but this may help
select convert(varchar(2), DATEPART(hour, getdate())) + convert(varchar(2), DATEPART(minute, getdate()))
0
 
sm394Commented:
here format options in detail
http://doc.ddart.net/mssql/sql70/ca-co_1.htm
0
 
zknollAuthor Commented:
convert(varchar(2), DATEPART(hour, getdate())) + convert(varchar(2), DATEPART(minute, getdate()))

This works for a time like 10:30.  The output is 1030 but if the time is 8:00:00 the output is 80 so I'm missing the leading 0 before the 8 and the second 0 for the minute.
0
 
zknollAuthor Commented:
It would have easier to understand if you referenced by field in the solution.  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.