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)
12/12/2017 23:04:37 15/12/2017 23:04:37 3 Days
12/12/2017 23:04:37 10/12/2017 23:04:37 - 2 Days
12/12/2017 23:04:37 15/01/2020 04:34:47 2 Years 1 Month 2 Days 5 Hours 30 Minutes 10 Seconds
12/12/2017 23:04:37 13/12/2017 02:30:37 3 Hours 26 Minutes
14/02/2015 15:12:30 12/12/2017 23:04:37 2 Years 9 Months 28 Days 7 Hours 52 Minutes 7 Seconds
02/01/1970 00:30:00 30/12/1969 00:00:00 - 3 Days 30 Minutes
Countdown for my birthday (2nd April) :
- 8 Months 10 Days 23 Hours 4 Minutes 37 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
12/12/2017 23:04:37 15/01/2018 23:04:37 34 Days to go [total days]
12/12/2017 23:04:37 12/02/2015 15:29:00 1034 Days passed [total days]
14/02/2015 15:29:00 12/12/2017 23:04:37 1486115 minutes to go [total minutes]
14/02/2015 15:29:20 12/12/2017 23:04:37 1488197 seconds to go [total seconds]