Question

In the db table the time is imported into a field with the following format h:mmt (12 hour:minutes AM/PM designator). The field is a varchar type field. I need to copy this into a field of type time.

I tried select CONVERT(time, '[Time]', 8) but I get the following error: Conversion failed when converting date and/or time from character string.

Any ideas on how I can convert and copy the varchar time to a type of time?

Was it helpful?

Solution

You just need to remove the quotes from around your column name, as you're trying to convert the word [Time] to a time, which won't work.

Try the below:

SELECT CONVERT(time, [Time], 8)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top