function FriendlyDateFromTo($p_from, $p_to) { /* CONVERT THE ISO DATES TO TIMESTAMPS*/ $v_from = DateToSeconds($p_from); $v_to = DateToSeconds($p_to); /* SPLIT THE DATES ABOVER INTO AN ARRAY */ $v_arr_from = split('[- :]', $p_from); $v_arr_to = split('[- :]', $p_to); /* CHECK IF IT'S TODAY */ $v_yesterday = mktime(0, 0, 0, date("m"), date("d") - 1, date("Y")); $v_tomorrow = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y")); if ($v_from > $v_yesterday && $v_to < $v_tomorrow && $v_from - $v_to < 86400) { return "Today " . $v_arr_from[3] . ":" . $v_arr_from[4] . " to " . $v_arr_to[3] . ":" . $v_arr_to[4]; } else { return Date("D", $v_from) . " " . Date("j", $v_from) . " " . Date("M", $v_from) . " " . $v_arr_from[3] . ":" . $v_arr_from[4] . " to " . Date("D", $v_to) . " " . Date("j", $v_from) . " " . Date("M", $v_from) . " " . $v_arr_to[3] . ":" . $v_arr_to[4]; } }
function TimestampTZToFriendly($t) { //echo $t."<br>"; $year = substr($t, 0, 4); $month = substr($t, 5, 2); $day = substr($t, 8, 2); $hour = substr($t, 11, 2); $min = substr($t, 14, 2); $sec = substr($t, 17, 2); //echo $year."-".$month."-".$day." ".$hour.":".$min.":".$sec."<br><hr>"; $date_seconds = DateToSeconds($t); $difference = time() - $date_seconds; //echo $difference."<br>"; if ($difference < 60) { return "Less than 1 minute ago"; } elseif ($difference < 3600) { return $min . " minutes ago"; } elseif ($difference < 86400) { return $hour . " hour(s) and " . $min . " mins ago"; } else { return $year . "-" . $month . "-" . $day; } }