Added getDateDiff function for return time diff

This commit is contained in:
Alfonso Saavedra "Son Link" 2024-12-30 19:49:07 +01:00
parent a14398f906
commit 166cfee7c3
No known key found for this signature in database
GPG key ID: D3594BCF897F74D8

View file

@ -439,3 +439,30 @@ function linkTitleImgTag(string $id, string $type, string $name, string $img): s
$content = $name . '<br />' . imgTag($img, '80px', $name);
return "<a href='$url'>$content</a>";
}
/**
* Return time diff between current date and period
* @param mixed $period
* @return int
*/
function getDateDiff($period)
{
switch ($period)
{
case 'today': //today
$datediff = 1 * 24 * 60 * 60;
return time() - $datediff;
case 'week': //last week
$datediff = 7 * 24 * 60 * 60;
return time() - $datediff;
case 'month': //last month
$datediff = 30 * 24 * 60 * 60;
return time() - $datediff;
case 'year': //last year
$datediff = 365 * 24 * 60 * 60;
return time() - $datediff;
default://always
$datediff = 50000 * 24 * 60 * 60;
return time() - $datediff;
}
}