Im using FullCalendar plugin to have a web calendar and show/insert events from my mysql table. It shows correctly the events from the bd but dont insert the date of the event in the correct format. (YYYY-MM-DD). Both columns of the mysql table are DATE type with the same format of the event that will be insert.
This is my JS script to show events and insert via ajax to mysql
$(document).ready(function() {
var date = new Date();
var dd = date.getDate();
var mm = date.getMonth();
var yyyy = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
editable: true,
events: "http://localhost/test-fullcalendar/php/eventos.php",
lang: "es",
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Evento a insertar:');
if (title) {
start = $.fullCalendar.moment('yyyy mm dd');
end = $.fullCalendar.moment('yyyy mm dd');
$.ajax({
url: 'http://localhost/test-fullcalendar/php/add_evento.php',
data: 'title='+ title+'&start='+ start +'&end='+ end ,
type: "POST",
success: function(json) {
alert('OK');
}
});
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true
);
}
calendar.fullCalendar('unselect');
}
});
});
The problem is with the function moment() of Fullcalendar on lines:
start = $.fullCalendar.moment('yyyy mm dd');
end = $.fullCalendar.moment('yyyy mm dd');
The function dont receive correctly the actual date and only insert "0000-00-00" on my table. I try to pass the date in the moment() argument like:
var date = yyyy + '-' + mm + '-' + dd;
start = $.fullCalendar.moment(date);
But it insert "0000-00-00" too.