0

I have defined my update query as follows to update a Date column.

declare @fromDate date;
set @fromDate = '2019-04-31'

update [dbo].[sites] 
  set [FromDate]= @fromDate 
where siteid=2832

Above gives following error:

Conversion failed when converting date and/or time from character string.

What Im doing wrong here?

1
  • 1
    That is teh catch thanks alot..im trying for an hour with this silly issue Commented Jun 12, 2019 at 2:16

2 Answers 2

3

April doesn't have 31 days, if you pass invalid date you will get error. Try with some valid date like 2019-04-30

Sign up to request clarification or add additional context in comments.

Comments

0

If it will work is most likely dependent on what settings you run on your server for dates. You can use CONVERT(datetime, '2019-04-31') this will convert any string to datetime type that your server supports.

2 Comments

When I do above conversion I get this error.//The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.//
@Ratha . . . If this isn't the problem, then the most likely issue is a trigger on the table. Have you looked at the triggers?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.