title: Event start time and end time does not show - Google Calendar with google-api-php-client
body: <pre><code>&lt;?php
  
  session_start();
  require_once 'google-api-php-client/src/Google_Client.php';
  require_once 'google-api-php-client/src/contrib/Google_CalendarService.php';
  
  $client = new Google_Client();
  $client-&gt;setApplicationName("Google Calendar PHP Starter Application");
  
  $client-&gt;setUseObjects(true);
  $cal = new Google_CalendarService($client);
  
  if (isset($_GET['logout'])) {
    unset($_SESSION['token']);
  }
  
  if (isset($_GET['code'])) {
    $client-&gt;authenticate($_GET['code']);
    $_SESSION['token'] = $client-&gt;getAccessToken();
    header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
  }
  
  if (isset($_SESSION['token'])) {
    $client-&gt;setAccessToken($_SESSION['token']);
  }
  
  $service = new Google_CalendarService($client);
  if ($client-&gt;getAccessToken()) {
      $_SESSION['token'] = $client-&gt;getAccessToken();
  }
  //$rightNow = date('c');
  //$params = array('singleEvents' =&gt; 'true', 'orderBy' =&gt; 'startTime', 'timeMin' =&gt; $rightNow);
  $rightNow = date('c');
  
  $tomorrow_in_seconds = 60 * 60 * 24;
  $tomorrow = date('yyyy-mm-dd', date("Y-m-d\Th:i:s", time() + $tomorrow_in_seconds));
  
  $params = array('singleEvents' =&gt; 'true', 'orderBy' =&gt; 'startTime', 'timeMin' =&gt; $rightNow, 'timeMax' =&gt; $tomorrow);
  $events = $service-&gt;events-&gt;listEvents('primary', $params);
  
  foreach ($events-&gt;getItems() as $event) {
          echo $event-&gt;getLocation()."&lt;br/&gt;";
          echo $event-&gt;when[0]-&gt;startTime;
          echo $event-&gt;when[0]-&gt;endTime;
  
          echo '-----&lt;br /&gt;';
  }
  
  
  ?&gt;
  </code></pre>
  
  <blockquote>
    <blockquote>
      <p>I get the location of the event. But cannot retrieve startTime and
      endTime. Also is there a way to show events of today only? Ultimately I want to show a pop on my website when the startTime and
      current time is same. So can anyone help me get StartTime?</p>
    </blockquote>
    
    <p>I have looked here :
    <a href="https://developers.google.com/google-apps/calendar/v3/reference/events/list" rel="nofollow">https://developers.google.com/google-apps/calendar/v3/reference/events/list</a>
    But it does not tell how to get startTime and end time. Which is
    really necessary.
    PHP is not my strongest point. So can anyone please help me?</p>
    
    <p>Thank you.</p>
    
    <hr>
    
    <p>After long long research I was able to extract the information. But could only do it with Zend Framework. Well hope this will be helpful for others.</p>
  </blockquote>
  
  <pre><code>require_once 'Zend/Loader.php';
      Zend_Loader::loadClass('Zend_Gdata');
      Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
      Zend_Loader::loadClass('Zend_Gdata_Calendar');
      Zend_Loader::loadClass('Zend_Http_Client');
  
      // create authenticated HTTP client for Calendar service
      $gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
      $user = "your-email@gmail.com";
      $pass = "your-password";
      $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
      $gcal = new Zend_Gdata_Calendar($client);
  
      // generate query to get event list
      $query = $gcal-&gt;newEventQuery();
      $query-&gt;setUser('default');
      $query-&gt;setVisibility('private');
      $query-&gt;setProjection('basic');
  
      // get and parse calendar feed
      // print output
      try {
        $feed = $gcal-&gt;getCalendarEventFeed($query);
      } catch (Zend_Gdata_App_Exception $e) {
        echo "Error: " . $e-&gt;getResponse();
      }
      ?&gt;
       &lt;h1&gt;&lt;?php echo $feed-&gt;title; ?&gt;&lt;/h1&gt; &lt;!-- displays email title --&gt;
      &lt;ol&gt;
  
      &lt;?php       
  
  
  
          $today = date('yyyy-mm-dd');
          $tomorrow = date(DateTime::ATOM, time()+(1 * 24 * 60 * 60));
  
          $gdataCal = new Zend_Gdata_Calendar($client);
          $query = $gdataCal-&gt;newEventQuery();
          $query-&gt;setUser('default');
          $query-&gt;setVisibility('private');
          $query-&gt;setProjection('full');
          $query-&gt;setOrderby('starttime');
          $query-&gt;setStartMin(date('Y-m-d 00:00:00'));
          $query-&gt;setStartMax(date('Y-m-d 23:59:59'));
  
          // echo date('Y-m-d G:i:s');
  
          $timestr = '2012-01-19T22:00:00.000-08:00';
          $date = new DateTime($timestr);
  
          // var_dump($date-&gt;format('d F  Y: H:i'));
  
          $eventFeed = $gdataCal-&gt;getCalendarEventFeed($query);
          echo "&lt;ul&gt;";
          echo "&lt;li&gt;";
          foreach ($eventFeed as $event) {
  
                  echo "&lt;ul&gt;";
  
                  foreach ($event-&gt;when as $when) {
  
                          echo "&lt;li&gt;Title: " . $event-&gt;title-&gt;text . "&lt;/li&gt;";
                          echo "&lt;li&gt;Location: ". $event-&gt;where[0]."&lt;/li&gt;";
                          echo "&lt;li&gt;Content: ".$event-&gt;content."&lt;/li&gt;" ;
                          $startDateTime = new DateTime($when-&gt;startTime);
                          $endDateTime = new DateTime($when-&gt;endTime);
                          echo "&lt;li&gt;Starts: " . $startDateTime-&gt;format('d F  Y: H:i'). "&lt;/li&gt;";
                          echo "&lt;li&gt;Ends: " . $endDateTime-&gt;format('d F  Y: H:i'). "&lt;/li&gt;";
                  }
  
                  echo "&lt;/ul&gt;";
                  echo "&lt;/li&gt;";
        }
  
        echo "&lt;/ul&gt;";
  </code></pre>
  
  <blockquote>
    <p>Sorry for messy code - i am still working on my unsolved part. But event retrieval is working...</p>
    
    <p>This is the output!</p>
  </blockquote>
  
  <pre><code>Title: Test event 4
  Location: International
  Content: Testing Email
  Starts: 06 June 2013: 21:00
  Ends: 06 June 2013: 22:00
  </code></pre>