0

I have json object with date field as dd/mm/yyyy. When I deserialized JObject to model I have date {1/1/0001 12:00:00 AM} and this is my problem.

    [HttpPost]
    public int SaveTimesheetList(JObject taskJson)
    {
        dynamic model = taskJson;

        var newTask = JsonConvert.DeserializeObject<TimesheetListModel>(model.ToString());

        return TimesheetService.SaveArbitraryTask(newTask, ProjectService.CurrentUserId);
    }

how to solve this?

HUSTLIN
  • 196
  • 4
  • 17
  • 2
    Per the [documentation](https://msdn.microsoft.com/en-us/library/system.data.sqltypes.sqldatetime(v=vs.110).aspx): "Represents the date and time data ranging in value from January 1, 1753 to December 31, 9999" - since your value isn't in that range, you need to spot that and adjust it. What value do you want to adjust it to? – Damien_The_Unbeliever Sep 11 '15 at 11:13
  • Man, I know it, but problem that is my date in json object is random date of 2015 year without the time, and when it's deserializing I have `{1/1/0001 12:00:00 AM}` – HUSTLIN Sep 11 '15 at 11:15
  • 1
    So what does the JSON look like? – Richard Schneider Sep 11 '15 at 11:17
  • I copied from visual studio debug window: `((Newtonsoft.Json.Linq.JContainer)(taskJson)) {\r\n "ProjectID": 4,\r\n "Date": "11/09/2015",\r\n "TaskDescription": "asdasdad",\r\n "TimeWorked": "4",\r\n "Note": null,\r\n "isSaved": true\r\n}` – HUSTLIN Sep 11 '15 at 11:28
  • 1
    Have you tried [setting the date format](http://stackoverflow.com/q/21256132/10263) used for deserialization? – Brian Rogers Sep 11 '15 at 13:47

0 Answers0