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/08/2017 04:15:06 24/08/2017 04:15:06 3 Days
21/08/2017 04:15:06 19/08/2017 04:15:06 - 2 Days
21/08/2017 04:15:06 23/09/2019 09:45:16 2 Years 1 Month 2 Days 5 Hours 30 Minutes 10 Seconds
21/08/2017 04:15:06 21/08/2017 07:41:06 3 Hours 26 Minutes
14/02/2015 15:12:30 21/08/2017 04:15:06 2 Years 6 Months 6 Days 13 Hours 2 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) :
- 4 Months 19 Days 4 Hours 15 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/08/2017 04:15:06 24/09/2017 04:15:06 34 Days to go [total days]
21/08/2017 04:15:06 12/02/2015 15:29:00 920 Days passed [total days]
14/02/2015 15:29:00 21/08/2017 04:15:06 1321966 minutes to go [total minutes]
14/02/2015 15:29:20 21/08/2017 04:15:06 1324666 seconds to go [total seconds]