To Cakephp team:
First see: Cake PHP 3.7 Date
I just tested the same query in laravel 5.8 and cakephp 4:
cakephp 4
public function itest()
{
$this->autoRender = false;
$petid = 9;
$pet = TableRegistry::getTableLocator()->get('Pets');
$data = $pet
->find()
->where(['petid' => $petid])
->first();
$testdate = $data->odate;
$json = json_encode($testdate);
echo $json;
exit();
}
}
Returns:
"1998-09-02T00:00:00+00:00"
Laravel 5.8
public function itest()
{
$petid = 9;
$pet = Pet::find($petid);
$testdate = $pet->odate;
$json = json_encode($testdate);
echo $json;
exit();
}
returns
"1998-09-02"
Why do you manipulate the orm and query builder to return what you want instead of a value that is actually stored.
I am not trying to cut anyone down, but I just don’t understand the core team manipulating users stored data.
In this case 1998-09-02 is what’s actually stored.
And I am not new to this stuff, I am currently number 14 on laravels top 50, I have used it since ver 4.2, and have used cakephp for some apps.
Why do you determine what’s returned instead of just letting mysql and pdo do their job.
I know I can do a work-a-round
public function itest()
{
$this->autoRender = false;
$petid = 9;
$pet = TableRegistry::getTableLocator()->get('Pets');
$data = $pet
->find()
->where(['petid' => $petid])
->first();
$testdate = new \DateTime($data->odate);
$newdate = $testdate->format('Y-m-d');
$json = json_encode($newdate);
echo $json;
exit();
}
Returns correctly:
"1998-09-02"
But shouldn’t have to do work a rounds.