Format all Date objects in Cakephp 3

Asked

Viewed 163 times

0

In my database I have some fields with the Date type. Therefore the data is stored in the format '2016-01-23'. However, when I retrieve this data to display it in the VIEW, it appears in the format '23/01/16' and I need to leave it in the format '23/01/2016'. I know I can use the $array->data->format(’d/m/Y') method to get this result. However, this would be very costly in terms of maintenance and productivity. Is there any way to format all Date type fields coming from the ORM in one place?

  • You can either format in PHP and it will be difficult, or in SELECT from the database you can use a DATE_FORMAT(campo_data, '%m-%d-%Y') and already bring formatted!

  • @Thiagosantos - Unfortunately it would not solve the issue of maintenance cost. I could also create a function to convert the date in the 'Entity' file related to 'View'. But I would also be in the same situation. Try to imagine a database with dozens of date fields distributing data to dozens of 'View'. Either the 'Date_format', '->format("d/m/Y") method or the use of functions would be costly to the project in terms of productivity and maintenance.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.