#Response json format date inconsistent between data type Date and Datetime

7 messages · Page 1 of 1 (latest)

teal nest
#

So i use sqlserver + laravel for my api running on Ubuntu 20.04 (apache2)
i have table1 with 2 columns , first column name is lets say date1(Date) and second one is date2(Datetime).

i use eloquent to retrieve data:

$result =MyModel::get();
and then response()->json($result);

the result is here :
{
"date1": "Oct 11 2023 12:00:00:AM",
"date2: "2023-10-11T05:55:56.000000Z"
}

but what i wanted is :
{
"date1": "2023-10-11",
"date2: "2023-10-11T05:55:56.000000Z"
}

what should i do to achieve this kind of behavior? this is happen on my new linux server (20.04) the old one is also Ubuntu 20.04 but working just fine... i've configured php,sqlserver,and my new linux server date,timezone,locales ... etc matched the old one.
any help or guide guys?

latent zodiac
#

You could format date in your response in the way you want it

#

in controller you should return YourNewResource::make($result);
and then in resource:
'date1' => $this->date1->format('Y-m-d')

teal nest
#

yes but those code above is just example i have huge codebase to refactor.. what im looking is like application wide setting

sleek mountain
latent zodiac
#

I see