7
I’m using a Json No Laravel 5 response, where I use Angular to display this data.
The date in Laravel is returned in format 2017-05-17 15:56:46
. When trying to use filter date
at the angle, continued displayed the same thing:
angular.module('app', []);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
{{ '2017-05-17 15:56:46' | date: 'dd/MM/yyyy' }}
</div>
In cases of dates in the above format, as I should do to be able to convert to the format dd/MM/yyyy
?
Don’t you have the option to format the date directly in php? I was suffering a lot with this too and decided to format the date at the time of
select
.– celsomtrindade
@celsomtrindade thinking of trying to do the
Carbon::setToStringFormat
work, but it’s bone– Wallace Maxters
I confess I don’t know much about Laravel, but what I did was
SELECT DATE_FORMAT(data '%d/%m/%Y') as 'data'
. Unless you need to work with the date directly in the view, then I don’t know if it would serve.– celsomtrindade
@My main concern is really to reach a standard. I could solve it like this, but every time I needed the formatted date, I would have to keep repeating it.
– Wallace Maxters
Yeah, that’s one of the cons of this method. Take a look at this one module, I used when I needed to work with several date manipulations, including showing messages like "17 minutes ago". Follows the same logic of the friend jbueno answer.
– celsomtrindade
@celsomtrindade to thinking about this initiative as well. I suggest you post an answer with Angular Moment. It’s an excellent alternative!
– Wallace Maxters