I need to convert Time value into integer value .
For E.g: If the time value is '07:00 PM' I need to convert it into 19.
I have tried below query to do this.
select CAST(substring(CONVERT(varchar,convert(smalldatetime,'07:00 PM'),114), 1,2) as int) as VALUE
It returns me the desired output. But it's taking too much time in case of big transactions. Can anyone suggest me an alternative solution ( a simple one perhaps)?
I can't use datepart(hour, 'timevalue'). Because there are data's with time value '00:00 AM'and'00:00 PM'which through's conversion error.In This case I need to return the value as 0.`
You seem to want to extract the hour from the time. Use datepart():
select datepart(hour, timecol)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With