Skip to content

Date modify returns invalid datetime #11368

Closed
@adamwpe

Description

@adamwpe

Description

Example: https://stackoverflow.com/questions/76384161/php-date-modify-returned-negative-microseconds

The following code:

<?php

$datetime = date_create('now');
$datetime->setTime(1,1,1,1 /* If set to any other number, it works fine */);
$datetime->modify('-100 ms');

var_dump($datetime);

Resulted in this output:

object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "2023-06-04 01:01:01.-99999"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}

But I expected this output instead:

object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "2023-06-04 01:01:00.900001"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}

PHP Version

7.2 and greater

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions