Why PHP is returning wrong days between two dates? -


there ton of such questions on stackoverflow , before mark duplicate, let me tell none of work in case.

date difference in php on days?

calculate difference between date/times in php

dates difference php

finding number of days between 2 dates

how calculate difference between 2 dates using php?

above questions have checked. last question has answer jurka unfortunately doesn't works. here code:

$date1 = new datetime(date('d-m-y')); $date2 = new datetime($etadate); $interval = $date1->diff($date2); echo "difference " . $interval->days . " days "; 

the $etadate in above case 03-02-16 , current date 08-02-16 should return 5 days returns high figure - 1826 days. have tried different methods returns same day figure.

a date value stored string in database on retrieving again putting date format using code:

$newdate = datetime::createfromformat('d-m-y', $entrydate); $newdate->add(new dateinterval('p15d')); $etadate = $newdate->format('d-m-y'); 

$entrydate variable holds date database, $etadate converts date format.

just change format of year y y , work.

see example : https://eval.in/514811


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -