sasafister's avatar

Fetch data from DB within last 24h, how can i do that?

As part of my web app http://zimoonline/clients/howdoyou i would like to show only database input's from last 24 hours, or maybe last week. How can i do that?

0 likes
8 replies
pobble's avatar

Do you have timestamps on the tables you want to get the data for?

sasafister's avatar

That works. Thanks again @jeffreyway, i had written something similiar, but i think that i didn't put ->get() at the end. Everything works just fine. Carbon is really awesome!

1 like
JeffreyWay's avatar

It is! Easily one of my favorite PHP packages.

If you want relative dates for when each mood was left, like "5 minutes ago," you can do $mood->created_at->diffForHumans().

sasafister's avatar

In meantime, is it good to keep all my varibales like this? http://laravel.io/bin/9378G

And one more question, how can i provide single variable for two or more views in controller? Do i have to use something like this?

View::composer('profile', function($view)
{
  $view->with('count', User::count());
});
vitormyra's avatar

You can do it - {{date("H", strtotime($variable))}}, you can use big H to your hour format be 24 hours and little h to your hour be 12 hours.

Please or to participate in this conversation.