php - Controlling output of time left -
i trying add php show time left prodcut on site, little bit auction. displays when time gets lower shows 0d 34h 12m means 0 days, 34 hours , 12 minutes, wondering if there way rid of 0d bit if there no days left bit 34h 12m, makes better, same when there no hours left , minutes.
here code calculates time left
$date = date('m/d/y h:i:s', time()); $date3 = new datetime($date); $date4 = new datetime($time_ending); $interval_date = $date3->diff($date4); $time_left = $interval_date->d."d ". $interval_date->h."h ". $interval_date->i."m "; is there anyway can this?
thanks help
yes, shortest way
$time_left = (($interval_date->d) ? $interval_date->d.'d ' : '') . (($interval_date->h) ? $interval_date->h.'h ' : '') . $interval_date->i.'m '; briefly explained (cond) ? (stma) : (stmb)
equals if(cond){ stma } else{ stmb }
Comments
Post a Comment