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)
28/06/2017 08:56:40 01/07/2017 08:56:40 3 Days
28/06/2017 08:56:40 26/06/2017 08:56:40 - 2 Days
28/06/2017 08:56:40 30/07/2019 14:26:50 2 Years 1 Month 2 Days 5 Hours 30 Minutes 10 Seconds
28/06/2017 08:56:40 28/06/2017 12:22:40 3 Hours 26 Minutes
14/02/2015 15:12:30 28/06/2017 08:56:40 2 Years 4 Months 13 Days 17 Hours 44 Minutes 10 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 26 Days 8 Hours 56 Minutes 40 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
28/06/2017 08:56:40 31/07/2017 08:56:40 33 Days to go [total days]
28/06/2017 08:56:40 12/02/2015 15:29:00 866 Days passed [total days]
14/02/2015 15:29:00 28/06/2017 08:56:40 1244187 minutes to go [total minutes]
14/02/2015 15:29:20 28/06/2017 08:56:40 1245800 seconds to go [total seconds]