date - Formatting php timedifference based on days -


i'm calculating timedifference bit of php , formatting in days, hours , minutes.

// compares expires_at current time $now = new datetime(); $future_date = new datetime($contest->expires_at);  $interval = $future_date->diff($now);  $enddate = $interval->format("%a days, %h hours, %i minutes");  // if current time higher expiration date set contest finished. if($now > $future_date) {     $enddate = 'date ended'; } 

now want have format display total amount of days when it's on day(24 hours) , start format in hours , minutes when it's less day(24 hours). format hours , minutes starting 23 hours 59 minutes, idea hopefully.

can tell me how done easiest?

do this:

// compares expires_at current time $now = new datetime(); $future_date = new datetime($contest->expires_at);  $interval = $future_date->diff($now);  if ($now > $future_date) {     // if current time higher expiration date set contest finished.     $enddate = 'date ended'; } else if ($interval >= new dateinterval("p1d")) {     $enddate = $interval->format("%a days, %h hours, %i minutes"); } else {     $enddate = $interval->format("%a days, %h hours, %i minutes"); } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -