PHP Counter Getting One Month Higher Than Expected [SOLVED] -


i'm building relationship counter profile how long has been in relationship or single.

the counter works, giving me 1 month above should be.

the php is:

<?php  function relationshiptime($relationshipdate) {      date_default_timezone_set("america/chicago");      $relationshipstart = $relationshipdate;      $todaysdate = date("m/d/y");      $diff = abs(strtotime($todaysdate) - strtotime($relationshipstart));      $years = floor($diff / (365 * 60 * 60 * 24));      $months = ceil(($diff - ($years * 365 * 60 * 60 * 24)) / ((365 * 60 * 60 * 24) / 12));      $months2 = floor(($diff - ($years * 365 * 60 * 60 * 24)) / ((365 * 60 * 60 * 24) / 12));      $days = floor(($diff - $years * 365 * 60 * 60 * 24 - $months2 * 30 * 60 * 60 * 24)/ (60 * 60 * 24));      echo $years . " years " . $months . " months " . $days . " days "; } ?> 

and then:

<?php relationshiptime("05/25/2015"); echo "single"; ?> 

which outputs:

0 years 1 months 20 days single 

but 5/25/2015 hasn't been month ago yet.

what causing 40 days ahead?

$months = floor(($diff - ($years * 365 * 60 * 60 * 24)) / ((365 * 60 * 60 * 24) / 12)); 

replace $months ceil floor.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -