title: DateTime with Timezone in php and Microsoft Graph API
body: <p>I'm trying to read the calendar entries of rooms and output the next three events on their calendar. However I am testing first to see if I can get just the first 3 events of the day, but it seems the timezone or something else is causing it to not show events correctly.</p>
  
  <p>This is a function I wrote:</p>
  
  <pre><code>function mb_get_meetings($mb_email = null, $mb_proxy = false, $mb_datetime_start = null, $mb_datetime_finish = null)
  {
      date_default_timezone_set('Australia/Melbourne');
  
      // get the Microsoft Open Graph API
      $mb_msgraph        = json_decode(mb_microsoft_opengraph($mb_proxy), true); // custom function to get Beaker Token + $mb_proxy for internal proxy on or off for dev testing
      $mb_msgraph_token    = $mb_msgraph['access_token'];
  
      $mb_datetimenow    = new DateTime();
      $mb_datetimezone    = new DateTimeZone('Australia/Melbourne');
      $mb_datetimenow-&gt;setTimezone($mb_datetimezone);
  
      $mb_datetime_start    = new DateTime($mb_datetime_start, $mb_datetimezone);
      $mb_datetime_finish = new DateTime($mb_datetime_finish, $mb_datetimezone);
  
      $mb_datetime_start    = $mb_datetime_start-&gt;format('Y-m-d\TH:i:s.u');
      $mb_datetime_finish = $mb_datetime_finish-&gt;format('Y-m-d\TH:i:s.u');
  
      $mb_url_string = 'https://graph.microsoft.com/v1.0/users/' . $mb_email . '/calendar/calendarView?startDateTime=' . $mb_datetime_start . '&amp;endDateTime=' . $mb_datetime_finish;
  
      $mb_args = array(
          'headers' =&gt; array(
              'Authorization'    =&gt; 'Bearer ' . $mb_msgraph_token,
              'Content-Type'    =&gt; 'application/x-www-form-urlencoded;charset=UTF-8',
              'Prefer'        =&gt; 'outlook.timezone="Australia/Melbourne"'
          ),
          'httpversion'    =&gt; '1.1'
      );
      $mb_output    = wp_remote_get($mb_url_string, $mb_args);
      $mb_output    = wp_remote_retrieve_body($mb_output);
      return $mb_output;
  }
  </code></pre>
  
  <p>I am using Wordpress as the backend and it does retrieve the body.</p>
  
  <p>In my frontend page I call:</p>
  
  <pre><code>$mbroom = (mb_get_meetings('email@domain.tld', true, 'today 7am', 'today 7pm'));
  $mbroom = json_decode($mbroom, true);
  $mbroom = $mbroom['value'];
  
  
  foreach ($mbroom as $k =&gt; $v) {
  
      // get the first 3 entries
      if ($k &lt; 3) {
  
          print_r($k);
          print_r($v['subject']);
          print_r(date('g:i', strtotime($v['start']['dateTime']));
          print_r(date('g:i', strtotime($v['end']['dateTime']));
          print_r($v['organizer']['emailAddress']['name']);
  
          echo '&lt;hr&gt;';
      }
  }
  </code></pre>
  
  <p>In the results, I will get sometimes no calendar entries while other times I might get entries for 2pm but not anything from 8am. I have tried changing it to hardcoded <code>YYYY-MM-DDD 08:00</code> and <code>YYYY-MM-DD 20:00</code> but to no avail. I have also tried <code>yesterday</code> and <code>tomorrow</code> but none/incorrect results.</p>
  
  <p>I also tried booking an entire day with 30-minute meetings and that too wasn't working.</p>
  
  <p>Am I doing something wrong?</p>