php - Store date values in Google Datastore -
i'm trying store date value in google datastore using google api php client service replies error:
invalid value for: invalid format: "2014-08-18 12:40:52" malformed @ " 12:40:52".
here's interesting section of code use:
function create_entity($name, $property, $data) { $entity = new google_service_datastore_entity(); $entity->setkey(createkey($name)); $string_prop = new google_service_datastore_property(); $string_prop->setstringvalue($data); $string_prop->setindexed(false); $time = date("y-m-d h:i:s"); $string_date = new google_service_datastore_property(); $string_date->setdatetimevalue($time); $string_date->setindexed(false); $property_map = []; $property_map[$property] = $string_prop; $property_map['date'] = $string_date; $entity->setproperties($property_map); return $entity; } function create_commit($name, $property, $data) { $entity = create_entity($name, $property, $data); $mutation = new google_service_datastore_mutation(); $mutation->setupsert([$entity]); $req = new google_service_datastore_commitrequest(); $req->setmode('non_transactional'); $req->setmutation($mutation); return $req; }
according cloud datastore docs, datetimevalue
property must string rfc 3339 formatted):
datetimevalue
: string (rfc 3339 formatted, milliseconds, instance2013-05-14t00:01:00.234z
)
Comments
Post a Comment