So far I have never had a problem putting a date only in json, use the php library, not cake.
Here is a c# example using Newtonsoft.Json
dynamic jsonobj = new Newtonsoft.Json.Linq.JObject();
jsonobj.petid = petid;
jsonobj.petname = petname;
jsonobj.odate = odate;
jsonobj.ocheck = ocheck;
string jsonText = jsonobj.ToString();
This is just a test database.
It returns:
{ "petid": "70", "petname": "Rover", "odate": "02/27/1990", "ocheck": "1" }
Notice the date:
You cannot store a datetime and expect just a date to be returned. You have to store a date only.
Testing in laravel, I also get correct results, but that’s using php.
If cakephp is not returning correct results, do a PR.
EDIT:
I just tested in cakephp ver 4
$pets = Pet::getPets($pages->getLimit2(), $pages->getPerpage());
$json = json_encode($pets);
echo $json;
Here is what I got:
{"petid":"9","petname":"BIGCAT","species":"CAT","sex":"F","ownerid":"4","petowner":"FRED","ostreet":"THE LONG WAY's","odate":"1998-09-02","ocheck":"1","dogpic":""}
Again notice the stored date of 1998-09-02 is put into json 1998-09-02.
So json_encode I double checked.
Don’t worry about the
$pages->getLimit2(), $pages->getPerpage() //part
Just custom code of mine.