Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Eg. Start Date 03 July 2015
End Date 04 July 2019

FY 15-16 364 days
FY 16-17 365 days
FY 17-18 365 days
FY 18-19 365 days
FY 19-20 4 day

What I have tried:

$date1 = "2010-06-01 22:45:00"; 

            $date2 = $nowDate;

            $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 days", $days);
Posted
Updated 28-Jun-21 15:40pm
v2

1 solution

1. convert each time to a unix timestamp
2. calculate the difference
3. divide by number of seconds in a day (86,400)
4. round down to nearest integer

PHP
<?php
	$stamp1 = strtotime($date1);
	$stamp2 = strtotime($date2);
	$deltaSeconds = abs($stamp2 - $stamp1);
	$deltaDays = floor( $deltaSeconds / (60 * 60 * 24) );
	printf("%d days<br>", $deltaDays);
?>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900