Created
August 1, 2015 07:40
-
-
Save phpfiddle/bb35c766e462dfeff79b to your computer and use it in GitHub Desktop.
[ Posted by Non_zero ] This is the code for getting date differences in php.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo 'For Yearly ::<br/>'; | |
$cur_datetime = new DateTime(); | |
echo '<br/>'.date('Y-m-d'); | |
echo '<br/>'; | |
$app_datetime = new DateTime("2014-08-02"); | |
echo date('2014-08-02'); | |
echo '<br/>'; | |
$difference = $cur_datetime->diff($app_datetime); | |
echo '<br/>'; | |
//yr diff: | |
if($difference->y>=1 && $difference->m>=0 && $difference->d>=0){ | |
echo 'Yr completed !!!<br/>'; | |
} | |
else{ | |
echo 'Yr not completed'; | |
echo 'Difference: '.$difference->y.' years, ' | |
.$difference->m.' months, ' | |
.$difference->d.' days'; | |
echo '<br/>'; | |
} | |
echo '<br/><br/><br/>'; | |
echo 'For Monthly::'; | |
$datetime_cur = new DateTime(); | |
echo '<br/>'.date('Y-m-d'); | |
echo '<br/>'; | |
$datetime_app = new DateTime('2014-05-01'); | |
echo '<br/>'.date('2014-05-01'); | |
echo '<br/>'; | |
$date_diff = $datetime_cur->diff($datetime_app); | |
if($date_diff->y >=0 && $date_diff->m >=1 && $date_diff->d ==0){ | |
echo 'Month completed.'; | |
echo 'Difference: '.$date_diff->y.' years, ' | |
.$date_diff->m.' months, ' | |
.$date_diff->d.' days'; | |
echo '<br/><br/><br/>'; | |
} | |
else{ | |
echo 'Month not completed.'; | |
echo 'Difference: '.$date_diff->y.' years, ' | |
.$date_diff->m.' months, ' | |
.$date_diff->d.' days'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment