title: Store date values in Google Datastore
body: <p>I'm trying to store a date value in Google Datastore using the <a href="https://github.com/google/google-api-php-client" rel="nofollow">Google API PHP Client</a> but the service replies always with an error: </p>
  
  <p>Invalid value for: Invalid format: "2014-08-18 12:40:52" is malformed at " 12:40:52".</p>
  
  <p>Here's the interesting section of the code I use:
  </p>
  
  <pre><code>function create_entity($name, $property, $data) {
      $entity = new Google_Service_Datastore_Entity();
      $entity-&gt;setKey(createKey($name));
  
      $string_prop = new Google_Service_Datastore_Property();
      $string_prop-&gt;setStringValue($data);
      $string_prop-&gt;setIndexed(false);
  
      $time = date("Y-m-d H:i:s");
  
      $string_date = new Google_Service_Datastore_Property();
      $string_date-&gt;setDateTimeValue($time);
      $string_date-&gt;setIndexed(false);
  
      $property_map = [];
      $property_map[$property] = $string_prop;
      $property_map['date'] = $string_date;
  
      $entity-&gt;setProperties($property_map);
  
      return $entity;
  }
  
  function create_commit($name, $property, $data) {
      $entity = create_entity($name, $property, $data);
  
      $mutation = new Google_Service_Datastore_Mutation();
      $mutation-&gt;setUpsert([$entity]);
  
      $req = new Google_Service_Datastore_CommitRequest();
      $req-&gt;setMode('NON_TRANSACTIONAL');
      $req-&gt;setMutation($mutation);
      return $req;
  }
  </code></pre>