Calculating difference between two dates in php

If date #1 is less than date #2 difference is positive, Used in cases where you need to calculate countdown or upcoming events.

 

If date #1 is more than date #2 difference is negative, Used in cases where you need to calculate past events, date of birth etc.

 

Date #1 (d/m/Y H:i:s) Date #2 (d/m/Y H:i:s) Difference (DATE1 - DATE2)
21/10/2017 10:25:06 24/10/2017 10:25:06 3 Days
21/10/2017 10:25:06 19/10/2017 10:25:06 - 2 Days
21/10/2017 10:25:06 23/11/2019 15:55:16 2 Years 1 Month 2 Days 5 Hours 30 Minutes 10 Seconds
21/10/2017 10:25:06 21/10/2017 13:51:06 3 Hours 26 Minutes
14/02/2015 15:12:30 21/10/2017 10:25:06 2 Years 8 Months 6 Days 19 Hours 12 Minutes 36 Seconds
02/01/1970 00:30:00 30/12/1969 00:00:00 - 3 Days 30 Minutes
Countdown for my birthday (2nd April) :
- 6 Months 19 Days 10 Hours 25 Minutes 6 Seconds
[reload and check again]
Date #1 (d/m/Y H:i:s) Date #2 (d/m/Y H:i:s) Difference (DATE1 - DATE2) in total
21/10/2017 10:25:06 24/11/2017 10:25:06 34 Days to go [total days]
21/10/2017 10:25:06 12/02/2015 15:29:00 981 Days passed [total days]
14/02/2015 15:29:00 21/10/2017 10:25:06 1409816 minutes to go [total minutes]
14/02/2015 15:29:20 21/10/2017 10:25:06 1413106 seconds to go [total seconds]