'ASP.NET MVC SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value

The Job model class has a column:

public DateTime JobDate { get; set; }

When I am trying to add a new Job, the input of JobDate is from

<input type="dateTime" name="JobDate" />

I get this error:

SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value

How can I fix it?



Solution 1:[1]

You have to change datatype of column "JobDate" in Database to datetime2

Refer: How to fix "SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value."

Solution 2:[2]

I recently ran into a similar issue. One solution I came across was to make the DateTime column nullable by adding a "?" to the model:

public DateTime? JobDate { get; set; }

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
Solution 2 JDevenyi