@ 2021-07-27T03:41:03Z <?php
date_default_timezone_set('UTC');
$begin = new \DateTime('2012-06-25');
$end = new \DateTime('2012-07-27');
$interval = $begin->diff($end);
$c = $interval;
$seconds = (($end->getTimestamp()) - ($begin->getTimestamp()));
// for DateTimeInterface::add()
$base = new \DateTimeImmutable('2012-07-02');
$end = new \DateTime('2012-08-03');
$interval = $base->diff($end);
$target = $base->add($interval);
$comparison = ((new \DateTime())->setTimestamp((($base->getTimestamp()) + $seconds)));
var_dump($target->format('Y-m-d'));
var_dump($comparison->format('Y-m-d'));
// for DateTimeInterval::sub()
$base = new \DateTimeImmutable('2012-08-03');
$target = $base->sub($interval);
$comparison = (new \DateTime())->setTimestamp($base->getTimestamp() - $seconds);
var_dump($target->format('Y-m-d'));
var_dump($comparison->format('Y-m-d'));
var_dump($seconds, $interval, $c);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.2.0 - 8.2.18 , 8.3.0 - 8.3.4 , 8.3.6 string(10) "2012-08-03"
string(10) "2012-08-03"
string(10) "2012-07-02"
string(10) "2012-07-02"
int(2764800)
object(DateInterval)#2 (10) {
["y"]=>
int(0)
["m"]=>
int(1)
["d"]=>
int(1)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["f"]=>
float(0)
["invert"]=>
int(0)
["days"]=>
int(32)
["from_string"]=>
bool(false)
}
object(DateInterval)#3 (10) {
["y"]=>
int(0)
["m"]=>
int(1)
["d"]=>
int(2)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["f"]=>
float(0)
["invert"]=>
int(0)
["days"]=>
int(32)
["from_string"]=>
bool(false)
}
Output for 8.3.5 Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
string(10) "2012-08-03"
string(10) "2012-08-03"
string(10) "2012-07-02"
string(10) "2012-07-02"
int(2764800)
object(DateInterval)#2 (10) {
["y"]=>
int(0)
["m"]=>
int(1)
["d"]=>
int(1)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["f"]=>
float(0)
["invert"]=>
int(0)
["days"]=>
int(32)
["from_string"]=>
bool(false)
}
object(DateInterval)#3 (10) {
["y"]=>
int(0)
["m"]=>
int(1)
["d"]=>
int(2)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["f"]=>
float(0)
["invert"]=>
int(0)
["days"]=>
int(32)
["from_string"]=>
bool(false)
}
Output for 7.1.0 - 7.1.33 , 7.2.0 - 7.2.34 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 string(10) "2012-08-03"
string(10) "2012-08-03"
string(10) "2012-07-02"
string(10) "2012-07-02"
int(2764800)
object(DateInterval)#2 (16) {
["y"]=>
int(0)
["m"]=>
int(1)
["d"]=>
int(1)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["f"]=>
float(0)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(32)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
object(DateInterval)#3 (16) {
["y"]=>
int(0)
["m"]=>
int(1)
["d"]=>
int(2)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["f"]=>
float(0)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(32)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
Output for 5.5.8 - 5.5.38 , 5.6.0 - 5.6.40 , 7.0.0 - 7.0.33 string(10) "2012-08-03"
string(10) "2012-08-03"
string(10) "2012-07-02"
string(10) "2012-07-02"
int(2764800)
object(DateInterval)#2 (15) {
["y"]=>
int(0)
["m"]=>
int(1)
["d"]=>
int(1)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(32)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
object(DateInterval)#3 (15) {
["y"]=>
int(0)
["m"]=>
int(1)
["d"]=>
int(2)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(32)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
Output for 5.5.0 - 5.5.7 Fatal error: DateTime::diff() must be derived from DateTimeImmutable::diff in Unknown on line 0
Process exited with code 255 . Output for 5.4.0 - 5.4.45 Fatal error: Class 'DateTimeImmutable' not found in /in/MKeKE on line 11
Process exited with code 255 . Output for 5.3.0 - 5.3.29 Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/MKeKE on line 15
Process exited with code 255 . Output for 4.4.2 - 4.4.9 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MKeKE on line 4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MKeKE on line 5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MKeKE on line 11
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MKeKE on line 12
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MKeKE on line 15
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/MKeKE on line 15
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 , 5.0.0 - 5.0.5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MKeKE on line 4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MKeKE on line 5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MKeKE on line 11
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MKeKE on line 12
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MKeKE on line 15
Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/MKeKE on line 15
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MKeKE on line 4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MKeKE on line 5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MKeKE on line 11
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MKeKE on line 12
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MKeKE on line 15
Parse error: parse error in /in/MKeKE on line 15
Process exited with code 255 . preferences:dark mode live preview
358.25 ms | 402 KiB | 468 Q