Reputation: 9692
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?
Upvotes: 0
Views: 66
Reputation: 427
April doesn't have 31 days, if you pass invalid date you will get error. Try with some valid date like 2019-04-30
Upvotes: 3
Reputation: 491
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.
Upvotes: 0