End Date needs to be the same as or later than the Start Date. Please use 'yyyy-mm-dd' format."; } //This inserts the date variables into the Google API request $response = file_get_contents("https://www.googleapis.com/calendar/v3/calendars/4fnme9rmk20odatisd2jks1pvo%40group.calendar.google.com/events?orderBy=startTime&singleEvents=true&timeMax=" . $EndDate . "T23%3A59%3A00-06%3A00&timeMin=" . $SttDate . "T03%3A00%3A00-06%3A00&fields=items(description%2Cend%2Clocation%2Cstart%2Csummary)&key=AIzaSyBoS0tmxAzRjdXkh_G1u5yu1ONua1MEo7s"); //The section below decodes the json response into an associative array. I have managed to work out how to populate the "array within an array" with entires for DATE format or DATETIME format. */ //this function should return the array within one of the results $decoded_response = json_decode($response, true); for ($i = 0; $i < count($decoded_response["items"]); $i++) { //Line below was a piece of debugging code //echo "".$i . " … ".count($decoded_response["items"])."…".($decoded_response['items'][$i]['start']['date'])."
"; //This handles the two different elements of the 'start' array within the 'items' array where the start and end dates might be stored if (isset($decoded_response['items'][$i]['start']['dateTime'])) { $start_GTime = ($decoded_response['items'][$i]['start']['dateTime']); $Gdate = new DateTime($start_GTime); echo "

" . $Gdate->format('l, M. j')."

"; echo "" . $Gdate->format('g:i a'); $end_GTime = ($decoded_response['items'][$i]['end']['dateTime']); $Gend = new DateTime($end_GTime); if ($Gdate<$Gend){ echo " - " . $Gend->format('g:i a');} echo " ♦ "; } if (isset($decoded_response['items'][$i]['start']['date'])) { $start_day = ($decoded_response['items'][$i]['start']['date']); $Gdate= new DateTime($start_day); echo "

" . $Gdate->format('l, M. j')."

"; } //prints out the rest of the event information echo "" . $decoded_response["items"][$i]["summary"] . "
"; echo $decoded_response["items"][$i]["location"] . "
"; echo nl2br($decoded_response["items"][$i]["description"]) . "

"; } echo "

"; ?>