'he conversion of a varchar data type to a datetime data type resulted in an out-of-range value
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
Solution 1:[1]
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:
You can use
set dateformat dmyat the top of your data insert file.But a better approach would be to use yyyy-mm-dd format.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shmiel |
