Skip to content
Advertisement

Why Week conversion failed in SQL Server in my case?

I am trying to convert week of the date based on my criteria.

My date condition: if my @date is less than 4 AM, then @date - 1, else @date

Output:

Now I want to find the week number of the output. So I tried

But I get this error:

The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

Advertisement

Answer

Just subtract four hours:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement