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)
30/04/2017 10:27:39 03/05/2017 10:27:39 3 Days
30/04/2017 10:27:39 28/04/2017 10:27:39 - 2 Days
30/04/2017 10:27:39 01/06/2019 15:57:49 2 Years 1 Month 2 Days 5 Hours 30 Minutes 10 Seconds
30/04/2017 10:27:39 30/04/2017 13:53:39 3 Hours 26 Minutes
14/02/2015 15:12:30 30/04/2017 10:27:39 2 Years 2 Months 15 Days 19 Hours 15 Minutes 9 Seconds
02/01/1970 00:30:00 30/12/1969 00:00:00 - 3 Days 30 Minutes
Countdown for my birthday (2nd April) :
- 28 Days 10 Hours 27 Minutes 39 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
30/04/2017 10:27:39 02/06/2017 10:27:39 33 Days to go [total days]
30/04/2017 10:27:39 12/02/2015 15:29:00 807 Days passed [total days]
14/02/2015 15:29:00 30/04/2017 10:27:39 1159258 minutes to go [total minutes]
14/02/2015 15:29:20 30/04/2017 10:27:39 1162699 seconds to go [total seconds]