Hello! I'm new in php-word and have one question.
Can you tell me how to get datediff like "34 days, 7 hours, 22 minutes" (for example) , when I compare Date from Database nad current date (now() ) ? Thank you!
Moderators: macek, egami, gesf

<?php
$startDate = strtotime("2012-01-01 15:38:45");//arbitrary time I have chosen for the example
$endDate = strtotime("2015-05-02 05:18:42");//arbitrary time I have chosen
$dateDiffInSeconds = $endDate - $startDate; //number of seconds that occur between the two.
//calculate years between not necessary for your request but lets make this scalable.
$numYears = floor($dateDiffInSeconds/(60*60*24*365));//total whole years between two dates
$remainder = $dateDiffInSeconds % (60*60*24*365);//number of seconds left after full years are removed
//calculate days from the remainder
$numDays = floor($remainder /(60*60*24));//total whole days, after years are removed, between two dates
$remainder = $remainder % (60*60*24);//number of seconds left after full days are removed
//calculate hoursfrom the remainder
$numHours = floor($remainder /(60*60));//total whole hours, after years & days are removed
$remainder = $remainder % (60*60);//number of seconds left after full years & days are removed
//calculate minutes from the remainder
$numMinutes = floor($remainder /60);
$remainder = $remainder % 60;
$numSeconds = $remainder;
?>





Users browsing this forum: No registered users and 1 guest