3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 00:00:00', new DateTimeZone("Europe/Amsterdam")); echo $birthday . "\n"; echo '<p>In the Netherlands Albert Einstein would now be ', $birthday->diff(new DateTime('00:00:00', 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 00:00:00', new DateTimeZone("Europe/London")); echo $birthday . "\n"; echo '<p>In the United Kingdom Albert Einstein would now be ', $birthday->diff(new DateTime('00:00:00', 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 00:00:00', new DateTimeZone("Europe/Amsterdam")); echo $birthday . "\n"; echo '<p>the Netherlands mr. Anonymous would now be ', $birthday->diff(new DateTime('00:00:00', 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 00:00:00', new DateTimeZone("Europe/London")); echo $birthday . "\n"; echo '<p>In the mr. Anonymous would now be ', $birthday->diff(new DateTime('00:00:00', 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 5.3.0 - 5.5.24, 5.6.0 - 5.6.8, 5.6.15 - 7.1.0
1879-03-14 00:00:00 <p>In the Netherlands Albert Einstein would now be 134 Years, 6 Months, 12 Days, 23 Hours, 59 Minutes, 32 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, 0 Hours, 0 Minutes, 0 Seconds old.</p>1950-03-14 00:00:00 <p>the Netherlands mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 0 Hours, 0 Minutes, 0 Seconds old.</p>1950-03-14 00:00:00 <p>In the mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 0 Hours, 0 Minutes, 0 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, 12 Days, 23 Hours, 59 Minutes, 32 Seconds old.</p>1879-03-14 00:00:00 <p>In the United Kingdom Albert Einstein would now be 134 Years, 6 Months, 12 Days, 23 Hours, 59 Minutes, 45 Seconds old.</p>1950-03-14 00:00:00 <p>the Netherlands mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 0 Hours, 0 Minutes, 0 Seconds old.</p>1950-03-14 00:00:00 <p>In the mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 0 Hours, 0 Minutes, 0 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/vieEN on line 28
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/vieEN 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/vieEN on line 14
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/vieEN 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/vieEN on line 14
Process exited with code 255.