user9582479
user9582479

Reputation: 83

The conversion of datetime2 date type to a datetime data type resulted in an out of range

I have JQuery DatePicker and I am getting this error.

ScheduleEntity :

public int ID{get;set;}
public string Title{get;set;}
public string Location{get;set;}
public DateTime Date{get;set;}

View :

<script>
    $(function(){
    $('#Date').datepicker{
    format:"dd/mm/yyyy"
    }).on('dp.change',function(e){
   $(this).data('datetimepicker').hide();
   });
</script>

I tried DataAnnotations datetime2 and Fluent API for datetime2 but not solved.

Upvotes: 0

Views: 451

Answers (1)

RickL
RickL

Reputation: 3393

If you're using EntityFramework, you can standardize to datetime2 in your DbContext class:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Properties<DateTime>().Configure(c => c.HasColumnType("datetime2"));
}

This has solved a number of DateTime issues for me in the past.

Upvotes: 1

Related Questions