Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

DateTime PHP Add days

I need to convert excel date to time stamp.

This is my code:

protected function convertExcelDateToTimestamp(int $offsetDays): ?int
{
    $start = DateTime::createFromFormat("Y-m-d H:i:s", '1900-01-01 00:00:00');
    $offsetDays = utf8_encode($offsetDays - 1);
    $start->modify("+" .$offsetDays. " day");
    if ($start->getTimestamp() === false) {
        var_dump(DateTime::getLastErrors(), $offsetDays);
    }
    return ($start->getTimestamp());
}

I have 2 issues.

  1. For each dates I'm always have + one day of the right result.
  2. For this excel date : 20/07/2050 the timestamp === to false And I don't have issue in DateTime::getLastErrors.

Some one have any idea why my code is wrong?

Comments