Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Calculate the difference between two dates in PHP?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 105
    Comment on it

    Hello readers, today we will discuss about "Calculating the difference between two dates in PHP".

    For example, we have 2 dates and we wants to find the difference between them in php so we can use the below code:

    $date1 = "2007-03-24";
    $date2 = "2009-06-26";
    
    $diff = abs(strtotime($date2) - strtotime($date1));
    
    $years = floor($diff / (365*60*60*24));
    $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
    $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
    
    printf("%d years, %d months, %d days\n", $years, $months, $days);
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: