0

I'm trying to update an event in a google calendar, i'm using the google calendar api, but when i'm trying to set the Start DateTime and the End DateTime of the event i'm getting this error:

 "code": 400, "message": "Start and end times must either both be date or both be dateTime." .

I've actually tried to format my date to ISO8601 and RF3339 but i'll get different type of errors where the format of the date was not valid

This is my code

$service = new Google_Service_Calendar($client);
  $event = $service->events->get($calendarID, $eventId);

$string_start_date ="12-07-2020 07:13:00"
  $start_date = new DateTime($string_start_date);
    $google_start_time = new Google_Service_calendar_eventDateTime();
      $google_start_time->setDateTime($start_date);

$string_end_date = "13-07-2020 12:00:00";
  $end_date = new DateTime($string_end_date);
    $google_end_time = new Google_Service_calendar_eventDateTime();
      $google_end_time->setDateTime($end_date);

$event->setDescription("description");
$event->setEnd($google_end_time);
$event->setStart($google_start_time);
$event->setSummary("summary");

$update = $service->events->update($calendarID, $eventId, $event);

and this is the content of my two google_service_calendar_eventDateTime objects:

1:object(Google_Service_Calendar_EventDateTime)#31 (6) { ["date"]=> NULL ["dateTime"]=> object(DateTime)#52 (3) { ["date"]=> string(26) "2020-07-12 07:13:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" } ["timeZone"]=> NULL ["internal_gapi_mappings":protected]=> array(0) { } ["modelData":protected]=> array(0) { } ["processed":protected]=> array(0) { } }

2:object(Google_Service_Calendar_EventDateTime)#58 (6) { ["date"]=> NULL ["dateTime"]=> object(DateTime)#73 (3) { ["date"]=> string(26) "2020-07-13 12:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" } ["timeZone"]=> NULL ["internal_gapi_mappings":protected]=> array(0) { } ["modelData":protected]=> array(0) { } ["processed":protected]=> array(0) { } }

1 Answers1

1

I've found a similar question thanks to @Nico Haase

This is the link where i found the answer

This is the updated code:

$end_date = new DateTime($string_end_date);
   $google_end_time = new Google_Service_calendar_eventDateTime();
     $google_end_time->setDateTime($end_date->format(\DateTime::RFC3339));