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)
24/01/2017 10:28:58 27/01/2017 10:28:58 3 Days
24/01/2017 10:28:58 22/01/2017 10:28:58 - 2 Days
24/01/2017 10:28:58 26/02/2019 15:59:08 2 Years 1 Month 2 Days 5 Hours 30 Minutes 10 Seconds
24/01/2017 10:28:58 24/01/2017 13:54:58 3 Hours 26 Minutes
14/02/2015 15:12:30 24/01/2017 10:28:58 1 Year 11 Months 9 Days 19 Hours 16 Minutes 28 Seconds
02/01/1970 00:30:00 30/12/1969 00:00:00 - 3 Days 30 Minutes
Countdown for my birthday (2nd April) :
2 Months 8 Days 13 Hours 31 Minutes 2 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
24/01/2017 10:28:58 27/02/2017 10:28:58 34 Days to go [total days]
24/01/2017 10:28:58 12/02/2015 15:29:00 711 Days passed [total days]
14/02/2015 15:29:00 24/01/2017 10:28:58 1021019 minutes to go [total minutes]
14/02/2015 15:29:20 24/01/2017 10:28:58 1024538 seconds to go [total seconds]