xref: /PHP-8.0/ext/date/tests/date_sub_basic.phpt (revision b5c7a83d)
1--TEST--
2Test date_sub() function : basic functionality
3--CREDITS--
4Felix De Vliegher <felix.devliegher@gmail.com>
5--FILE--
6<?php
7date_default_timezone_set('UTC');
8echo "*** Testing date_sub() : basic functionality ***\n";
9
10// Initialise all required variables
11$startDate = '2008-01-01 12:25';
12$format = 'Y-m-d H:i:s';
13$intervals = array(
14    'P3Y6M4DT12H30M5S',
15    'P0D',
16    'P2DT1M',
17    'P1Y2MT23H43M150S'
18);
19
20$d = new DateTime($startDate);
21var_dump( $d->format($format) );
22
23foreach($intervals as $interval) {
24    date_sub($d, new DateInterval($interval) );
25    var_dump( $d->format($format) );
26}
27
28?>
29--EXPECT--
30*** Testing date_sub() : basic functionality ***
31string(19) "2008-01-01 12:25:00"
32string(19) "2004-06-26 23:54:55"
33string(19) "2004-06-26 23:54:55"
34string(19) "2004-06-24 23:53:55"
35string(19) "2003-04-24 00:08:25"
36