how can i categorize database rows by
today
yesterday
last 7 days
last 30 days
how can i categorize database rows by
today
yesterday
last 7 days
last 30 days
Here is a function for checking post time:
$post_time1 = strtotime("05 December 2015");
$post_time2 = strtotime("02 December 2015");
check_post_time($post_time1);
check_post_time($post_time2);
function check_post_time($time) {
$before_24 = strtotime("-1 day");
$before_1week = strtotime("-1 week");
$before_1month = strtotime("-1 month");
if($time >= $before_24)
echo "24hr ago";
elseif($time >= $before_1week)
echo "between 24hr - 1 week ago";
elseif($time >= $before_1month)
echo "between 7 days - 1 month ago";
else
echo "1 month ago";
}
You can use Carbon PHP package to display your time in human readable way. This package is very popular and it even included on the Laravel framework.
You can install the package using Composer
. Once you installed this package you can use it by following like this:
<?php
require 'vendor/autoload.php';
use Carbon\Carbon;
printf("Now: %s", Carbon::now());
// Human readable way
echo Carbon::now()->subMinutes(2)->diffForHumans(); // '2 minutes ago'