Question

It retrieving date time 06/03/2014 12:00:00 AM and end date is 31/03/2015 12:00:00 AM but in my jquery alert message is showing like this /9413044200000/ i dontknow whats a problem i need to set min date and max date in datepicker pls some one help me. . .

My JsonResult

public JsonResult GroupName(string tourname, string MatchType)
    {                                   
        var sdate = entity.TblTournaments.FirstOrDefault(x => x.Torname == tourname && x.Recordstatus == 1).TourStartdate;
        var edate = entity.TblTournaments.FirstOrDefault(x => x.Torname == tourname && x.Recordstatus == 1).TourEnddate;
        var data = new { sdate, edate };
        return Json(data, JsonRequestBehavior.AllowGet);
    }

and my jquery is

     $.post("/BindInventory/GroupName", { tourname: tname, MatchType: MatchType }, function (result) {                      
                   var startdate = result.sdate;
                   var enddate = result.edate;
                   alert(result.sdate);
                   $('#date').datepicker('option', 'minValue', new Date(startdate));
                   $('#date').datepicker('option', 'maxValue', new Date(enddate));
               }, "json");
Was it helpful?

Solution

You need to parse JSON - date with:

var date = new Date(parseInt(jsonDate.substr(6)));

Source here: https://stackoverflow.com/a/2316066/1278667

EDIT: In your case:

$.post("/BindInventory/GroupName", { tourname: tname, MatchType: MatchType }, function (result) {                      
               var startdate = new Date(parseInt(result.sdate.substr(6)));
               var enddate = new Date(parseInt(result.edate.substr(6)));
               $('#date').datepicker('option', 'minValue', startdate);
               $('#date').datepicker('option', 'maxValue', enddate);
           }, "json");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top