bircastri
bircastri

Reputation: 2165

How to convert time String to datetime?

I want to convert a String to datetime.

So I'm building this code:

SELECT CONVERT(datetime, '23:00', 103)

If I try to execute this code I have this:

1900-01-01 23:00:00.000

But if I try to execute this convert:

SELECT CONVERT(datetime, '24:00', 108)

I have this error:

Converting a varchar data type to datetime generated a value not within the range of allowed values.

Upvotes: 0

Views: 73

Answers (1)

Vladyslav Yefremov
Vladyslav Yefremov

Reputation: 368

Datetime type does not support "24th hour". Its time range is 00:00:00 through 23:59:59.997.

Try use instead

SELECT CONVERT(datetime, '00:00', 108)

For more details check datetime (Transact-SQL) page.

Upvotes: 2

Related Questions