$array = array('start'=>"new Date(".date("Y",strtotime($start_date)).")");
$myJson = json_encode($array);
The returned json is a string, how can i convert the dates to objects? I'm using the jquery calendar plugin and it wants a date object. Thanks!
Send a date string normally with json and then parse it with javascript:
var d = Date.parse("Jul 8, 2005");
Reference: http://www.w3schools.com/jsref/jsref_parse.asp
Instead of trying to send javascript to the browser send just a unix timestamp and make a date with that on the server
PHP
echo json_encode(array('start' => mktime(date("Y",strtotime($start_date)))));
JS
var val = JSON.parse(json);
var date = new Date(val['start']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With