I'm pretty new to Parse.com. I've been using the PHP SDK to try and populate some data. I've had no issues so far other than not being able to set date values against objects that have a column of type "Date".
My code:
$uploadDate = date("Y-m-d\TH:i:s.u",$instaPost->created_time);
echo $uploadDate;
$photo->set('uploadDate',$uploadDate);
$photo->save();
The echo call returns: 2015-10-06T19:33:36.000000
Parse gives me an error of: Failed to create new object, with error message: invalid type for key uploadDate, expected date, but got string
I have also tried:
$uploadDate = array(
"__type" => "Date",
"iso" => date("c", time())
);
and various other combinations and date formats (the first parameter of the date() function).
Does anyone know the correct way of doing this??
Php date() function returns string. So $uploadDate is of type string. But when you try to set it for column type date it is giving error. This should solve your problem.
$date = array(
"__type" => "Date",
"iso" => date("c", $instaPost->created_time)
);
$photo->set('uploadDate',$date);
$photo->save();
I was having the same problem. You are doing it correctly, but you are missing one thing.
Instead of using: $photo->set('uploadDate',$uploadDate);
try this: $photo->setArray('uploadDate',$uploadDate);
I'm also using this function that I found on the parse.com forum:
function getProperDateFormat($value)
{
$dateFormatString = 'Y-m-d\TH:i:s.u';
$date = date_format($value, $dateFormatString);
$date = substr($date, 0, -3) . 'Z';
return $date;
}
where $value is a php Date object.
So this is how I put all together:
$date = new DateTime($year."-".$month."-".$day);
$puzzle->setArray( "date", ["__type" => "Date", "iso" => getProperDateFormat($date)] );
It works perfectly for me