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/03/2017 03:25:55 27/03/2017 03:25:55 3 Days
24/03/2017 03:25:55 22/03/2017 03:25:55 - 2 Days
24/03/2017 03:25:55 26/04/2019 08:56:05 2 Years 1 Month 2 Days 5 Hours 30 Minutes 10 Seconds
24/03/2017 03:25:55 24/03/2017 06:51:55 3 Hours 26 Minutes
14/02/2015 15:12:30 24/03/2017 03:25:55 2 Years 1 Month 9 Days 12 Hours 13 Minutes 25 Seconds
02/01/1970 00:30:00 30/12/1969 00:00:00 - 3 Days 30 Minutes
Countdown for my birthday (2nd April) :
8 Days 20 Hours 34 Minutes 5 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/03/2017 03:25:55 27/04/2017 03:25:55 34 Days to go [total days]
24/03/2017 03:25:55 12/02/2015 15:29:00 770 Days passed [total days]
14/02/2015 15:29:00 24/03/2017 03:25:55 1105976 minutes to go [total minutes]
14/02/2015 15:29:20 24/03/2017 03:25:55 1109315 seconds to go [total seconds]