I am tinkering with the Jquery Weekly Calendar Plugin (Which you can look at the full demo here: skedyul.herokuapp.com)
Now, I'm trying to put some events dynamically using PHP but I'm fairly new to the concept of JSON.
This is my example php array to be encoded to JSON:
<?php
$events = array(
array(
"id" => 1,
"start" => date("D M j Y H:i:s "),
"end" => date("D M j Y H:i:s ",strtotime("+30 minutes")),
"title" => "College Algebra"
),
array(
"id" => 2,
"start" => date("D M j Y H:i:s ",strtotime("+30 minutes +1 day")),
"end" => date("D M j Y H:i:s ",strtotime("+45 minutes +1 day")),
"title" => "Calculus"
)
);
?>
And here is the working Javascript code with some sample data:
<script type="text/javascript">
function getEventData() {
var year = new Date().getFullYear();
var month = new Date().getMonth();
var day = new Date().getDate();
console.log(new Date(year, month, day, 12));
return {
events : [
{
"id":1,
"start": new Date(year, month, day, 12),
"end": new Date(year, month, day, 13, 30),
"title":"College Algebra",
},
{
"id":2,
"start": new Date(year, month, day, 14),
"end": new Date(year, month, day, 14, 45),
"title":"Statistics and Probability"
}
]
};
}
And here, I changed the above Javascript into this (putting the json encoded php associative array)
<script type="text/javascript">
function getEventData() {
var year = new Date().getFullYear();
var month = new Date().getMonth();
var day = new Date().getDate();
console.log(new Date(year, month, day, 12));
return {
events : <?php echo json_encode($events)?>
};
}
</script>
It's seems to work an doesn't spews out errors but the problem is about the Date. It's not showing properly at the calendar..
How do I correctly pass JSON from PHP with dates? Thank you :)