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

Since version 4.2, Laravel converts date/time fields to Carbons instances. See more here http://laravel.com/docs/4.2/eloquent#date-mutators

This means you can do:

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

Thanks MateusAzevedo but this solution not work show this error

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

0

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.
0

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.
0

Try:

<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. https://github.com/briannesbitt/Carbon

Last updated 9 years ago.

zouhair liked this reply

1

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

$OpenOrders=DB::table('users_agents')
			->join('mt4_trades','mt4_trades.LOGIN', '=', 'users_agents.id_mt4_user')
			->join('users', 'users.id', '=', '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

0

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.

example

$c->created_at->diffForHumans();

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

$OpenOrders->OPEN_TIME->diffForHumans();

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>

https://github.com/LaravelIO/laravel.io/search?utf8=%E2%9C%93&q=created_ago

Last updated 9 years ago.
0

Very Thanks for replay MateusAzevedo , DonaldRecord , adamkearsley , Kryptonit3

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.