Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Čamo's avatar
Level 3

Date formating for json response

Hi there, I need to make an ajax request to collection but the date fields in entities are in a raw format. How can I send formated dates in json response? Hope it is possible. Thanks for any help.

0 likes
7 replies
Čamo's avatar
Level 3

There is no simpler way to do it? I think some kind of getter?

jlrdw's avatar

I use:

$tdate = new \DateTime($array[$i][2]);  // comes in comma delimited format
$ndate = $tdate->format('Y-m-d');

$ndate is properly formatted date.

You could use a helper if wanted, an accessor, whatever.

Note, I am old school I still like "getter, setter".

1 like
martinbean's avatar

@Čamo Dates in resources don’t come in a “raw” format, but rather ISO 8601 format. ISO 8601-formatted dates are supported in pretty much every programming language, including JavaScript.

Čamo's avatar
Level 3

Yes but I dont want to mess with dates in javascript. Hope mess is the right word...

Please or to participate in this conversation.