title: How to Convert DateTime to String?
body: <p>I have an array of DateTime objects and need to use them as strings in a function call. I have tried casting it like <code>$string_datetime = (string)$myDateTimeObject;</code> but that doesn't work. Searching has been unfruitful as well, as most people are asking how to convert a string to DateTime instead. </p>
  
  <p>My Code:</p>
  
  <pre><code>$start_date = new DateTime();
  $end_date = new DateTime();
  $end_date = $end_date-&gt;modify('+1 day');
  
  // Add time range to request
  $request['time_range'] = Array ( 'start' =&gt; $start_date,
                                   'end'   =&gt; $end_date);
  </code></pre>
  
  <p>When calling a function which expects a string (it's an API call) I receive this error:</p>
  
  <blockquote>
    <p>Catchable fatal error: Object of class DateTime could not be converted to string</p>
  </blockquote>
  
  <p>What's the correct way of converting/extracting a string from a DateTime object?</p>