3v4l.org

run code in 300+ PHP versions simultaneously
<?php // example to show the magic date 1937-07-01 change in the NL // the Zend\Validate\DateStep does not account for this difference class Blar_DateTime extends DateTime { /** * Return Date in ISO8601 format * * @return String */ public function __toString() { return $this->format('Y-m-d H:i:s'); } /** * Return difference between $this and $now * * @param Datetime|String $now * @return DateInterval */ public function diff($now = 'NOW', $absolute = NULL) { if(!($now instanceOf DateTime)) { $now = new DateTime($now); } return parent::diff($now); } /** * Return Age in Years * * @param Datetime|String $now * @return Integer */ public function getAge($now = 'NOW') { return $this->diff($now)->format('%y'); } } $birthday = new Blar_DateTime('1879-03-14', new DateTimeZone("Europe/Amsterdam")); echo $birthday; echo '<p>In the Netherlands Albert Einstein would now be ', $birthday->diff(new DateTime('NOW', new DateTimeZone("Europe/Amsterdam")))->format('%y Years, %m Months, %d Days, %h Hours, %i Minutes, %s Seconds'), ' old.</p>'; $birthday = new Blar_DateTime('1879-03-14', new DateTimeZone("Europe/London")); echo $birthday; echo '<p>In the United Kingdom Albert Einstein would now be ', $birthday->diff(new DateTime('NOW', new DateTimeZone("Europe/London")))->format('%y Years, %m Months, %d Days, %h Hours, %i Minutes, %s Seconds'), ' old.</p>'; $birthday = new Blar_DateTime('1950-03-14', new DateTimeZone("Europe/Amsterdam")); echo $birthday; echo '<p>the Netherlands mr. Anonymous would now be ', $birthday->diff(new DateTime('NOW', new DateTimeZone("Europe/Amsterdam")))->format('%y Years, %m Months, %d Days, %h Hours, %i Minutes, %s Seconds'), ' old.</p>'; $birthday = new Blar_DateTime('1950-03-14', new DateTimeZone("Europe/London")); echo $birthday; echo '<p>In the mr. Anonymous would now be ', $birthday->diff(new DateTime('NOW', new DateTimeZone("Europe/London")))->format('%y Years, %m Months, %d Days, %h Hours, %i Minutes, %s Seconds'), ' old.</p>'; // output /* 1879-03-14 00:00:00 In the Netherlands Albert Einstein would now be 134 Years, 5 Months, 14 Days, 17 Hours, 54 Minutes, 49 Seconds old. 1879-03-14 00:00:00 In the United Kingdom Albert Einstein would now be 134 Years, 5 Months, 14 Days, 16 Hours, 55 Minutes, 17 Seconds old. 1950-03-14 00:00:00 the Netherlands mr. Anonymous would now be 63 Years, 5 Months, 14 Days, 17 Hours, 55 Minutes, 17 Seconds old. 1950-03-14 00:00:00 In the mr. Anonymous would now be 63 Years, 5 Months, 14 Days, 16 Hours, 55 Minutes, 17 Seconds old. now note the difference in seconds between example 1 and 2 of 28 seconds... exactly the time that does not exists in the netherlands on 1937-07-01 I conclude PHP does it correctly and Zend\Validate\DateStep should account for this. */
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Return type of Blar_DateTime::diff($now = 'NOW', $absolute = null) should either be compatible with DateTime::diff(DateTimeInterface $targetObject, bool $absolute = false): DateInterval, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/3iO2j on line 24 1879-03-14 00:00:00<p>In the Netherlands Albert Einstein would now be 134 Years, 6 Months, 13 Days, 19 Hours, 13 Minutes, 52 Seconds old.</p>1879-03-14 00:00:00<p>In the United Kingdom Albert Einstein would now be 134 Years, 6 Months, 13 Days, 18 Hours, 13 Minutes, 52 Seconds old.</p>1950-03-14 00:00:00<p>the Netherlands mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 19 Hours, 13 Minutes, 52 Seconds old.</p>1950-03-14 00:00:00<p>In the mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 18 Hours, 13 Minutes, 52 Seconds old.</p>
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.24, 5.6.0 - 5.6.8, 5.6.15 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
1879-03-14 00:00:00<p>In the Netherlands Albert Einstein would now be 134 Years, 6 Months, 13 Days, 19 Hours, 13 Minutes, 24 Seconds old.</p>1879-03-14 00:00:00<p>In the United Kingdom Albert Einstein would now be 134 Years, 6 Months, 13 Days, 18 Hours, 13 Minutes, 52 Seconds old.</p>1950-03-14 00:00:00<p>the Netherlands mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 19 Hours, 13 Minutes, 52 Seconds old.</p>1950-03-14 00:00:00<p>In the mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 18 Hours, 13 Minutes, 52 Seconds old.</p>
Output for 5.5.25 - 5.5.38, 5.6.9 - 5.6.14
1879-03-14 00:00:00<p>In the Netherlands Albert Einstein would now be 134 Years, 6 Months, 13 Days, 19 Hours, 13 Minutes, 24 Seconds old.</p>1879-03-14 00:00:00<p>In the United Kingdom Albert Einstein would now be 134 Years, 6 Months, 13 Days, 18 Hours, 13 Minutes, 37 Seconds old.</p>1950-03-14 00:00:00<p>the Netherlands mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 19 Hours, 13 Minutes, 52 Seconds old.</p>1950-03-14 00:00:00<p>In the mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 18 Hours, 13 Minutes, 52 Seconds old.</p>
Output for 5.2.0 - 5.2.17
1879-03-14 00:00:00<p>In the Netherlands Albert Einstein would now be Fatal error: Call to undefined method DateTime::diff() in /in/3iO2j on line 28
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/3iO2j on line 7
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/3iO2j on line 14
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/3iO2j on line 14
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/3iO2j on line 14
Process exited with code 255.

preferences:
266.42 ms | 401 KiB | 385 Q