Francesco Francesco - 1 year ago 116
PHP Question

Store date values in Google Datastore

I'm trying to store a date value in Google Datastore using the Google API PHP Client but the service replies always with an error:

Invalid value for: Invalid format: "2014-08-18 12:40:52" is malformed at " 12:40:52".

Here's the interesting section of the code I use:

function create_entity($name, $property, $data) {
$entity = new Google_Service_Datastore_Entity();

$string_prop = new Google_Service_Datastore_Property();

$time = date("Y-m-d H:i:s");

$string_date = new Google_Service_Datastore_Property();

$property_map = [];
$property_map[$property] = $string_prop;
$property_map['date'] = $string_date;


return $entity;

function create_commit($name, $property, $data) {
$entity = create_entity($name, $property, $data);

$mutation = new Google_Service_Datastore_Mutation();

$req = new Google_Service_Datastore_CommitRequest();
return $req;

Answer Source

According to the Cloud Datastore docs, the dateTimeValue property must be a string that is RFC 3339 formatted):

dateTimeValue: string (RFC 3339 formatted, with milliseconds, for instance 2013-05-14T00:01:00.234Z)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download