PHP: Get Differences Date from Minutes to (Year, Month, Day, Hour, Minute)


This program will be uses php's STRTOTIME function to get the difference two dates. It will display either in year, month, week, day, hour or minute.

The php function:

function get_ago($minute)
{
    $ago = "";
    if ($minute > 525949 ) {
        $ago = round($minute/525949)." Year Ago";
    } else if ($minute > 43829) {
        $ago = round($minute/43829)." Month  Ago";
    } else if ($minute > 10080) {
        $ago = round($minute/10080)." Week  Ago";
    } else if ($minute > 1440) {
        $ago = round($minute/1440)." Day  Ago";
    } else if ($minute > 60) {
        $ago = round($minute/60)." Hour  Ago";
    } else if ($minute > 0) {
        $ago = round($minute)." Minute  Ago";
    } else {
        $ago = "1 Minute  Ago";
    }
    return $ago;
}

The Calling function:

$to_time = strtotime(date("Y-m-d H:i:s")); //current date
$from_time = strtotime("2012-11-20 20:30:30");
$ago = get_ago(round(abs("$to_time - $from_time") / 60,2));


Popular Posts

.

Sila Klik, Untuk  Menempah Web Profesional!
Facebook Page
Facebook Page
Back to Top