Reputation: 24903
http://arshaw.com/fullcalendar/ I want to create an event on my server when the select function is called.
This is my code:
select: function(start, end, allDay) {
$.ajax({
type: "POST",
url: "/account/availability",
data: {action: "create", start: start, end: start},
success: function(id) {
calendar.fullCalendar('renderEvent',{
title: "My Event",
start: start,
end: end,
allDay: true,
id: id
});
}
});
}
The problem is, that the dates of start and end are in a weired format, like this "Thu Jan 09 2014 00:00:00 GMT+0100 (Mitteleuropäische Zeit)". How can I convert that format into a php, so that I can save these events easily into my database?
Upvotes: 0
Views: 4586
Reputation: 15574
Hi I had the same kind of problem but in javaScript
. But I used the fullCalander built-in function to that.
var dd = $.fullCalendar.formatDate(date,"yyyy-MM-dd");
Check my SO question here.
Upvotes: 1
Reputation: 978
You can do it like so using fullcalendar convert date function
select: function(start, end, allDay) {
//$.fullCalendar.formatDate( date, formatString [, options ] ) -> String
// Notice that i used the variable assign to calendar var
// var calendar = $('#calendar').fullCalendar({ .....
var startDate = calendar.formatDate( start, "yyyy-MM-dd");
var endDate = calendar.formatDate( end, "yyyy-MM-dd");
$.ajax({
type: "POST",
url: "/account/availability",
data: {action: "create", start: start, end: start},
success: function(id) {
calendar.fullCalendar('renderEvent',{
title: "My Event",
start: start,
end: end,
allDay: true,
id: id
});
}
});
}
Upvotes: 0
Reputation: 791
Just use strtotime, some times strtotime will not work in strings with some locations like this one, so make sure you clean your values, in this example i used explode.
$date = 'Thu Jan 09 2014 00:00:00 GMT+0100 (Mitteleuropäische Zeit)';
$time = strtotime(current(explode("(",$date)));
echo Date('Y / M / d', $time);
Working example here: example
Upvotes: 1