Question

I have Date data and converted to string "2014-04-16 08:27:52" from my local PostgreSQL.

Please explain me how to set it at Parse.com as Date datatype?

No correct solution

OTHER TIPS

In the docs on rest API search on date and see the json type and format :

"__type":"Date","iso":"2011-08-21T18:02:52

That would be Included in the date elements json used in the post.

I just figured it out:

var date = new Date("2014-04-16 08:27:52");
object.set("last_update",date);

In PHP, you can do:

$parse->someDate = $parse->dataType( 'date', '1985-01-01' );

In JavaScript, you can do:

var someDate = new Date("1985-01-01");
yourclass.set( 'someDate', { "__type": "Date", "iso": someDate.toISOString() } );

For Parse.com and PHP, the answer is less straight forward than what is presented here. It took me a while to figure out that dataType() isn't working for some reason in the SDK.

It seems many people got the $parse->dataType() syntax from here. But I can't find this function anymore in the official SDK.

Then there is this bug and the resulting function from StackOverflow, but neither of these are very user friendly.

As it turns out, the Parse PHP SDK will handle an array for the value in the createdAt, updatedAt, and other special data types.

This code works (essentially a direct port from their REST API / JavaScript):

$query->greaterThanOrEqualTo("createdAt", ["__type" => "Date", "iso" => date('Y-m-01\TH:i:s')]);

Feel free to use that format for other special types, like GeoPoints.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top