Skip to content
PHP Logo

How can the leap year bug in Excel for the year 1900 impact date calculations when converting Excel dates to PHP dates?

The leap year bug in Excel for the year 1900 causes Excel to incorrectly consider 1900 as a leap year, which can lead to date miscalculations when converting Excel dates to PHP dates. To solve this issue, we need to account for this bug by adjusting the date conversion process in PHP.

php
function excelToPHPDate($excelDate) {
    if ($excelDate < 60) {
        $excelDate++;
    }
    return date('Y-m-d', strtotime('1899-12-30') + ($excelDate - 1) * 86400);
}