I'm creating a JavaScript based calendar, using full-calendar.js as main backbone.
So in other to insert a new event
into a MySQL database, I have the following code snippet:
$.post("http://localhost/calendar/index.php/calendar/insert_event",
{
title : title,
start : start,
end : end,
allDay : allDay,
url : ''
},
function(answer) {
console.log(answer);
}
);
the start
and end
dates are simply Date()
objects:
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
in the calendar.php
controller, I get the following output:
{"title":"lunch",
"start":"Tue Oct 08 2013 08:00:00 GMT-0700 (Pacific Standard Time)",
"end":"Tue Oct 08 2013 08:30:00 GMT-0700 (Pacific Standard Time)",
"allDay":"false",
"url":""}
start
and end
are DATETIME
Types in a MySQL table where the columns have the same type was above.
When I do the insert
using CodeIgniter's
Active Record functions, it inserts to the table without further problems. However, when I look at the MySQL
database to see the output, I see:
mysql> select * from calendar_utility;
+----+-----+-------+---------------------+---------------------+--------+
| id | url | title | start | end | allday |
+----+-----+-------+---------------------+---------------------+--------+
| 1 | | lunch | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | 0 |
+----+-----+-------+---------------------+---------------------+--------+
1 row in set (0.00 sec)
How can I correct format the JavaScript
Date()
to insert correctly at the MySQL db?