Support the ongoing development of →
Views Packages
Last updated 2 years ago.

Since version 4.2, Laravel converts date/time fields to Carbons instances. See more here

This means you can do:

<td>{{ $OpenOrders->OPEN_TIME->format('Y-m-d')}}</td>

Thanks MateusAzevedo but this solution not work show this error

Call to a member function format() on a non-object


See the link I posted above. If i'm not wrong, you should tell Laravel what fields needs to be converted. By default, just created_at and updated_at are converted.

If this not work, you can use default PHP date conversion (look at PHP docs).

Last updated 9 years ago.

Before you get to this, how are you getting $OpenOrders? Please show us the code, because that may have something to do with your problem

Last updated 9 years ago.


<td>{{ \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $OpenOrders->OPEN_TIME)->format('Y-m-d') }}</td> 

This isn't best practise... In reality, you should be converting the format before you send the variable to the view. Please do some research into the Carbon date formatting that comes with Laravel, its very easy to implement.

Last updated 9 years ago.

zouhair liked this reply


If convert datetime to date in query how make this in code

			->join('mt4_trades','mt4_trades.LOGIN', '=', 'users_agents.id_mt4_user')
			->join('users', '', '=', 'users_agents.id_user')
if (!empty($aFilters['OPEN_TIME'])) {

			$OpenOrders->Where('mt4_trades.OPEN_TIME', '=',  $aFilters['OPEN_TIME']);


in where statment mt4_trades.OPEN_TIME how to convert datetime to date in cloumn 'OPEN_TIME'? Thanks


I personally do not want to mess with the headache of converting and displaying timezones properly so with my project, the site uses one timezone (laravel default) and the user never actually sees a REAL time. I show them the "difference" with laravels diffForHumans function.



when chained right after a "time" element it will show something like this "1 day ago" or "3 hours ago" or "20 minutes ago"

personal preference. most users won't care EXACTLY when something occurs and everything on the back end sees and sorts by the actual time when i sort.

so it would be


The comments on this thread use this as well as you can see. They use a function in their comment creator class

 public function created_ago()
    return $this->resource->created_at->diffForHumans();

and in their view for the comment in the loop

<li>posted {{ $reply->created_ago }}</li>

Last updated 9 years ago.

Very Thanks for replay MateusAzevedo , DonaldRecord , adamkearsley , Kryptonit3


Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.