Within a index.blade.php
I have a variable:
<td>{{$ordemjoin->dataplanejamento}}</td>
The date comes out in English format. How do I put it in Brazilian format?
Note: version of Laravel 5.2
Within a index.blade.php
I have a variable:
<td>{{$ordemjoin->dataplanejamento}}</td>
The date comes out in English format. How do I put it in Brazilian format?
Note: version of Laravel 5.2
This should work:
<td>{{ date( 'd/m/Y' , strtotime($ordemjoin->dataplanejamento))}}</td>
DB does not have any all the features offered by Eloquent , then do the right SQL
: DATE_FORMAT(dataplanejamento,'%d/%m/%Y') as dataplanejamentobr
DB::select("SELECT tabela.*,
DATE_FORMAT(dataplanejamento,'%d/%m/%Y') as dataplanejamentobr from tabela");
<td>{{$ordemjoin->dataplanejamentobr}}</td>
If you do not want to do so, you can work with strtotime with date , but, create a file of helpers
and put a function to not be repeating code:
function date_br($value, $format='d/m/Y')
{
return date($format, strtotime($value));
}
<td>{{date_br($carros->dataplanejamento)}}</td>
Recommendation:
If you start using Eloquent you will notice the programming gain in relation to using the DB class example of course I'll illustrate would be the Date Mutators in the class configuration, example :
No array
of $dates
enter the date
or datetime
field in your case dataplanejamento
:
class Carros extends Model
{
protected $dates = [
'created_at',
'updated_at',
'deleted_at',
'dataplanejamento'
];
}
in your Views file ( blade
) could do it like this:
<td>{{$carros->dataplanejamento->format('d/m/Y')}}</td>
It would be very easy and could format your date.
Apparently by what you describe in the question and in the comments, the object must be a string. In this case the following example should solve:
{{Carbon\Carbon::parse($ordemjoin->dataplanejamento)->format('d/m/Y')}}
If the object is a Carbon
, just invoke the format()
method directly from the object itself.
{{$ordemjoin->dataplanejamento->format('d/m/Y')}}