0

I have a column OFFSTARTIME with a datetime datatype. Currently data is appearing as

1900-01-01 08:00:00.000

I want to show only

08:00:00

For that I have tried the following query:

SUBSTRING(CAST(OFFSTARTIME AS VARCHAR(19)), 12, 19)

but it's showing an output of

0 8:00AM
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Deepak Jain
  • 137
  • 1
  • 3
  • 27

2 Answers2

2

There is datatype for time only, it's time datatype :)

Try cast(offstarttime as time).

If you really want to cast, then cast it to varchar and use right function: right(cast(offstarttime as varchar(23)), 12)

Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69
1

You have to convert value to varchar to get requested output as below. check other formats as well

DECLARE @myTime Datetime='1900-01-01 08:00:00.000'

SELECT CONVERT(VARCHAR(8), @myTime, 108)