Home > front end >  he conversion of a varchar data type to a datetime data type resulted in an out-of-range value
he conversion of a varchar data type to a datetime data type resulted in an out-of-range value

Time:04-28

I Created a table dbo.CovidStats with columns ( covidId(int PK), covidDate(datetime), confirmcases(int),Death(int),country(varchar),flag(bit), totalLoss(int) )

I executed this query

INSERT INTO dbo.CovidStats VALUES('27/04/2022', 5500, 10, 'USA', 1, 500000); 

and I got this error:

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

when i removed the string from the date i got a Default date of 1900-01-01. in the column

help please

CodePudding user response:

The reason you get this error is because the system doesn't recognize dd-mm-yyyy as a date format by default.

To solve this you have 2 options:

  1. You can use set dateformat dmy at the top of your data insert file.

  2. But a better approach would be to use yyyy-mm-dd format.

  • Related