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/02/2018 16:35:11 24/02/2018 16:35:11 3 Days
21/02/2018 16:35:11 19/02/2018 16:35:11 - 2 Days
21/02/2018 16:35:11 23/03/2020 22:05:21 2 Years 1 Month 2 Days 5 Hours 30 Minutes 10 Seconds
21/02/2018 16:35:11 21/02/2018 20:01:11 3 Hours 26 Minutes
14/02/2015 15:12:30 21/02/2018 16:35:11 3 Years 7 Days 1 Hour 22 Minutes 41 Seconds
02/01/1970 00:30:00 30/12/1969 00:00:00 - 3 Days 30 Minutes
Countdown for my birthday (2nd April) :
- 10 Months 19 Days 16 Hours 35 Minutes 11 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/02/2018 16:35:11 24/03/2018 16:35:11 31 Days to go [total days]
21/02/2018 16:35:11 12/02/2015 15:29:00 1105 Days passed [total days]
14/02/2015 15:29:00 21/02/2018 16:35:11 1588326 minutes to go [total minutes]
14/02/2015 15:29:20 21/02/2018 16:35:11 1588671 seconds to go [total seconds]