Saturday, May 18, 2013

Compute difference between two dates in php

5/18/2013

This php script explain you , how you can calculates the difference of time between them in years, months, days.


<?php
/* 
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/

$date_1 = "2007-03-24";
$date_2 = "2013-06-01";

$diff = abs(strtotime($date_2) - strtotime($date_1));

$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);


?>

helpful? Share this

The Editorial Team of 4everTutorials consists of a group of PHP Professionals.

0 comments:

 

© 2014 4everTutorials. All rights resevered.

Back To Top