Skip to content

Instantly share code, notes, and snippets.

@shiraliali
Last active January 21, 2023 22:16
Show Gist options
  • Save shiraliali/2cc4a64dcf8acd96d25d93842ae19386 to your computer and use it in GitHub Desktop.
Save shiraliali/2cc4a64dcf8acd96d25d93842ae19386 to your computer and use it in GitHub Desktop.
PHP function for messure remaining days between two unix time format
/**
* messureSubscriptionDays
* Returns messured days based on unix time format.
* @param mixed $subscription
* @return void
*
*/
function messureSubscriptionDays($subscription)
{
$now = time(); // current time in unix format
$remainTimeUnix = $subscription - $now; // messure the difference of $now and passed unix time as $subscription parameter
$remainDays = $remainTimeUnix / 86400; // divide the difference by a day long in unix time format
return substr($remainDays, 0, 3); // add offset on float messured number by first 3 character.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment