3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $datetime1 = new DateTime(); $datetime2 = new DateTime('2014-03-10 11:13:00'); $interval = $datetime1->diff($datetime2); $elapsed = $interval->format('%y years, %m months, %a days, %h hours, %i minutes, %S seconds'); $elapsed = str_replace(array('0 years,', ' 0 months,', ' 0 days,', ' 0 hours,', ' 0 minutes,'), '', $elapsed); $elapsed = str_replace(array('1 years, ', ' 1 months, ', ' 1 days, ', ' 1 hours, ', ' 1 minutes'), array('1 year, ', '1 month, ', ' 1 day, ', ' 1 hour, ', ' 1 minute'), $elapsed); echo $elapsed;
Output for 5.4.26, 5.6.28, 7.0.14 - 7.1.0
2 hours, 22 seconds
Output for 7.0.6
2 years,1 month, 784 days, 14 hours, 59 minutes, 04 seconds
Output for 7.0.5
2 years, 754 days, 4 hours, 14 minutes, 15 seconds
Output for 7.0.4
1 year, 11 months, 730 days, 13 hours, 42 minutes, 31 seconds
Output for 7.0.3
2 years, 738 days, 13 hours, 54 minutes, 44 seconds
Output for 7.0.2
2 years, 742 days, 29 minutes, 51 seconds
Output for 7.0.1
2 years, 744 days, 41 minutes, 34 seconds
Output for 7.0.0
2 years, 747 days, 3 hours, 12 minutes, 57 seconds
Output for 5.6.21
2 years,1 month, 783 days, 10 hours, 1 minute, 21 seconds
Output for 5.6.20
2 years, 760 days, 23 hours, 29 minutes, 05 seconds
Output for 5.6.19
1 year, 11 months, 727 days, 11 hours, 57 minutes, 51 seconds
Output for 5.6.18
2 years, 734 days, 23 hours, 37 minutes, 12 seconds
Output for 5.6.17
2 years, 739 days, 18 hours, 23 minutes, 42 seconds
Output for 5.6.16
2 years, 748 days, 4 hours, 58 minutes, 01 seconds
Output for 5.6.15
2 years, 749 days, 5 hours, 51 minutes, 36 seconds
Output for 5.6.14
2 years, 753 days, 8 hours, 30 minutes, 06 seconds
Output for 5.6.13
2 years,1 month, 766 days, 12 hours, 18 minutes, 02 seconds
Output for 5.6.12
2 years,1 month, 771 days, 1 hour, 26 minutes, 08 seconds
Output for 5.6.11
2 years,1 month, 774 days, 8 hours, 42 minutes, 23 seconds
Output for 5.6.10
2 years,1 month, 776 days, 10 hours, 22 minutes, 23 seconds
Output for 5.6.9
2 years,1 month, 778 days, 15 hours, 31 minutes, 32 seconds
Output for 5.6.8
2 years,1 month, 780 days, 23 hours, 6 minutes, 45 seconds
Output for 5.6.7
2 years, 2 months, 806 days, 9 hours, 47 minutes, 06 seconds
Output for 5.5.35
2 years, 2 months, 803 days, 13 hours, 21 minutes, 38 seconds
Output for 5.5.34
2 years,1 month, 762 days, 5 hours, 24 minutes, 44 seconds
Output for 5.5.33
1 year, 11 months, 729 days, 36 minutes, 40 seconds
Output for 5.5.32
2 years, 737 days, 6 hours, 17 minutes, 16 seconds
Output for 5.5.31
2 years, 740 days, 21 hours, 16 minutes, 41 seconds
Output for 5.5.30
2 years, 752 days, 7 hours, 53 minutes, 02 seconds
Output for 5.5.29
2 years,1 month, 768 days, 2 hours, 24 minutes, 40 seconds
Output for 5.5.28
2 years,1 month, 772 days, 4 hours, 40 minutes, 32 seconds
Output for 5.5.27
2 years,1 month, 773 days, 7 hours, 14 minutes, 03 seconds
Output for 5.5.26
2 years,1 month, 777 days, 12 hours, 39 minutes, 46 seconds
Output for 5.5.25
2 years,1 month, 779 days, 18 hours, 47 minutes, 57 seconds
Output for 5.5.24
2 years,1 month, 782 days, 2 hours, 19 minutes, 17 seconds
Output for 5.4.45
1 year, 6 months, 552 days, 16 hours, 49 minutes, 43 seconds
Output for 5.4.44
1 year, 6 months, 552 days, 16 hours, 49 minutes, 40 seconds
Output for 5.4.43
1 year, 6 months, 552 days, 16 hours, 49 minutes, 37 seconds
Output for 5.4.42
1 year, 6 months, 552 days, 16 hours, 49 minutes, 36 seconds
Output for 5.4.41
1 year, 6 months, 552 days, 16 hours, 49 minutes, 33 seconds
Output for 5.4.40
1 year, 2 months, 426 days, 5 hours, 25 minutes, 16 seconds
Output for 5.4.39
1 year, 2 months, 426 days, 5 hours, 25 minutes, 15 seconds
Output for 5.4.38
11 months, 357 days, 2 hours, 18 minutes, 32 seconds
Output for 5.4.36 - 5.4.37
10 months, 334 days, 22 hours, 7 minutes, 55 seconds
Output for 5.4.34 - 5.4.35
10 months, 334 days, 22 hours, 7 minutes, 54 seconds
Output for 5.4.32
5 months, 180 days, 21 hours, 12 minutes, 02 seconds
Output for 5.4.31
5 months, 180 days, 21 hours, 11 minutes, 59 seconds
Output for 5.3.29, 5.4.28 - 5.4.30
5 months, 180 days, 21 hours, 11 minutes, 56 seconds
Output for 5.4.27
5 months, 180 days, 21 hours, 12 minutes, 00 seconds
Output for 5.4.5 - 5.4.25
2 hours, 21 seconds
Output for 5.3.13 - 5.3.28, 5.4.0 - 5.4.4
2 hours, 20 seconds
Output for 5.3.0 - 5.3.12
2 hours, 19 seconds
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined method DateTime::diff() in /in/LBe5p on line 4
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/LBe5p on line 2
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: datetime in /in/LBe5p on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: datetime in /in/LBe5p on line 2