Grigor
Grigor

Reputation: 4049

PHP Expires In Script

I have a row in database table which has a value in seconds, which is how many seconds remains for premium membership to expire (it might be 1 month in seconds, or 25 days in seconds etc)

I am trying to make a script where if there are less than 30 days remaining, it will say for example,

25 d 14 h 45 m

or if its less than a day it will just say

14 h 45 m

and if it is less than an hour it will just say how many minutes remain. I tried to search in google for this but I didn't know what to search for (search term).

Upvotes: 0

Views: 188

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324650

Apparently you already have the "separate the time into units" part nailed, so here's how to remove empty parts:

if( $months > 0) echo $months."mo ";
if( $months+$days > 0) echo $days."d ";
if( $months+$days+$hours > 0) echo $hours."h ";
echo $minutes."m";

This will allow you to get things like "1d 0h 0m", but not "0d 1h 2m".

Upvotes: 1

Related Questions