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)
27/02/2017 07:25:25 02/03/2017 07:25:25 3 Days
27/02/2017 07:25:25 25/02/2017 07:25:25 - 2 Days
27/02/2017 07:25:25 29/03/2019 12:55:35 2 Years 1 Month 2 Days 5 Hours 30 Minutes 10 Seconds
27/02/2017 07:25:25 27/02/2017 10:51:25 3 Hours 26 Minutes
14/02/2015 15:12:30 27/02/2017 07:25:25 2 Years 12 Days 16 Hours 12 Minutes 55 Seconds
02/01/1970 00:30:00 30/12/1969 00:00:00 - 3 Days 30 Minutes
Countdown for my birthday (2nd April) :
1 Month 5 Days 16 Hours 34 Minutes 35 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
27/02/2017 07:25:25 30/03/2017 07:25:25 31 Days to go [total days]
27/02/2017 07:25:25 12/02/2015 15:29:00 745 Days passed [total days]
14/02/2015 15:29:00 27/02/2017 07:25:25 1069976 minutes to go [total minutes]
14/02/2015 15:29:20 27/02/2017 07:25:25 1073285 seconds to go [total seconds]