php - Getting days from DateTime() above 30/31 so it doesn't carry over to months -
i'm calculating difference between 2 dates using datetime() , it's working fine. problem want have days format able go above full month 30/31 or higher.
$now = new datetime(); $future_date = new datetime($contest->expires_at); $interval = $future_date->diff($now); $enddate = $interval->format("%m month, %d days, %h hours, %i minutes");
the current problem when don't display months, days can go 30/31 , on carried on make new month resetting days count leftover days. want able display 42 days when difference 6 weeks kind of format:
$enddate = $interval->format("%d days, %h hours, %i minutes");
is there quick fix or need manually convert timestamp seconds , use own function modulus operators this?
you can try:
$enddate = $interval->format("%a days, %h hours, %i minutes");
see dateinterval::format in manual.
note
take care of bug if you're working on windows.