1

I am using php to send some data to fullcalendar, but the calendar dates display as Invalid Date or NaN

see the date formatting below, any ideas how to fix this?

PHP

foreach ($dates as $key => $date) {
    //$date->getDate() is a timestamp
    $start = new DateTime($date->getDate());
    $end   = new DateTime($date->getDate() + 1800);

    $array[$key]['start']       = $start->format('c');
    $array[$key]['end']         = $end->format('c');
}

JavaScript

$calendar.fullCalendar({
    header     : h,
    defaultView: 'month',
    slotMinutes: 15,
    editable   : false,
    droppable  : false,
    events     : {
        url : '/api',
        type: 'POST',
        data: data
    }
});

edit:

I end up using:

$dA = date('Y-m-d H:i:s', $date->getDate());
$datetimeA = new DateTime($dA);

$array[$key]['start'] = $datetimeA->format(DateTime::ISO8601);
Patrioticcow
  • 26,422
  • 75
  • 217
  • 337

1 Answers1

0

It is because the date is formatted incorrectly, Firefox require the UTC format to work, which is:

 yyyy + '-' + mm + '-' + dd + 'T' + hh + ':' + min + 'Z';

behing yyyy the year formatted at 4 digits, mm the month formatted at 2 digits (January - 00, the zero is important), dd the day formatted at 2 digits, hh the hour formatted at 2 digits and min the minutes formatted at 2 digits.

T and Z are constants.

so just change your format to this if you want with hours and minutes:

$array[$key]['start']       = $start->format('Y-m-d\TH:i:s\Z');
$array[$key]['end']         = $end->format('Y-m-d\TH:i:s\Z');

hope this works. Do tell me if it doesn't and we will try to solve it :)

Pedro Silva
  • 263
  • 2
  • 17
  • actually i see that fullcalendar sends `Invalid date` on FF rather then the current date.. – Patrioticcow Jul 14 '15 at 22:54
  • `Z` isn't actually a constant, but rather an indicator of **Z**ulu (UTC) timezone -- http://stackoverflow.com/questions/833102/wheres-the-datetime-z-format-specifier – drzaus Sep 07 '16 at 12:52