Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The JSON value could not be converted to System.DateTime [duplicate]

I have an Employee table

public class Employee
{
   [Key]
   public long ID { get; set; }
   public DateTime EmpDate { get; set; }
   public string FirstName { get; set; }
   public string LastName { get; set; }
}

I have created web API to post the employee data:

[HttpPost]
public async Task<ActionResult<Employee>> PostLead(Employee employee)
{
      //Code to post
}

This is my JSON body

{
    "firstname":"xyz",
    "lastname":"abc",
    "EmpDate":"2019-01-06 17:16:40"
}

I am getting error as The JSON value could not be converted to System.DateTime. But when I pass EmpDate value as 2019-01-06, I am not getting an error.

like image 508
Adi Avatar asked Jan 22 '20 19:01

Adi


1 Answers

your date value in your JSON isn't correct. should be

2019-01-06T17:16:40

Most parsers use ISO 8601

like image 141
Sean Avatar answered Sep 26 '22 06:09

Sean