From f64ab630fdf13080675bff28b66acc86f90680a3 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Mon, 5 Jun 2023 12:25:39 -0400 Subject: [PATCH] Added TimeAgo Function to convert mysql DataTime to a human readable time like 2 weeks ago similar to other apps like facebook do it. Added to function to Recent Activity under client overview --- client_overview.php | 5 ++--- functions.php | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/client_overview.php b/client_overview.php index b248b79e..0441d07d 100644 --- a/client_overview.php +++ b/client_overview.php @@ -114,13 +114,12 @@ $sql_asset_retire = mysqli_query( - + diff --git a/functions.php b/functions.php index d2cb9668..3ea2722b 100644 --- a/functions.php +++ b/functions.php @@ -653,3 +653,29 @@ function sanitizeForEmail($data) { $sanitized = trim($sanitized); return $sanitized; } + +function timeAgo($datetime) { + $time = strtotime($datetime); + $difference = time() - $time; + + if ($difference < 1) { + return 'just now'; + } + $timeRules = array ( + 31536000 => 'year', + 2592000 => 'month', + 604800 => 'week', + 86400 => 'day', + 3600 => 'hour', + 60 => 'minute', + 1 => 'second' + ); + + foreach ($timeRules as $secs => $str) { + $div = $difference / $secs; + if ($div >= 1) { + $t = round($div); + return $t . ' ' . $str . ($t > 1 ? 's' : '') . ' ago'; + } + } +}