Karthik Karthik - 4 years ago 160
PHP Question

Find Month difference in php?

Is there any way to find the month difference in PHP? I have the input of from-date 2003-10-17 and to-date 2004-03-24. I need to find how many months there are within these two days. Say if 6 months, I need the output in months only. Thanks for guiding me for day difference.

I find the solution through MySQL but I need it in PHP. Anyone help me, Thanks in advance.

Answer Source

Here's a quick one:

$date1 = mktime(0,0,0,10,0,2003); // m d y, use 0 for day
$date2 = mktime(0,0,0,3,0,2004); // m d y, use 0 for day

echo round(($date2-$date1) / 60 / 60 / 24 / 30);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download