Last active
December 20, 2017 07:26
-
-
Save mazfreelance/6287d99df2d5dd841b899964b2f04301 to your computer and use it in GitHub Desktop.
PHP: calculate days between two date given (database & original)
This file contains hidden or 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
//from php | |
$date1 = date_create('2017-10-10'); | |
$date2 = date_create('2017-10-15'); | |
$diff = date_diff($date1,$date2); | |
echo $diff->format("%R%a days"); // +14 days - %R is +/- | %a is number | |
//from database to php | |
$y = date('Y', strtotime($desc['gep_startdate'])); | |
$m = date('n', strtotime($desc['gep_startdate'])); | |
$date1 = date_create($desc['gep_startdate']); | |
$date2 = date_create(date($y.'-'.$m.'-27')); | |
$diff = date_diff($date1,$date2); | |
echo $diff->format("%R%a days"); // +20 days |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment