nuovo / spreadsheet-reader

A PHP spreadsheet reader (Excel XLS and XLSX, OpenOffice ODS, and variously separated text files) with a singular goal of getting the data out, efficiently
http://www.nuovo.lv/
Other
674 stars 497 forks source link

Date not usable #171

Open vgout69 opened 3 years ago

vgout69 commented 3 years ago

Hello,

I'm really sorry this post could be due to my lack of experience in using dates but, I can't retrieve ccorrect date from the CSV files I'm using. Dates are with this format mm/dd/YYYY and displayed with Excel as mm.dd.YYYY. When I go through my rows, I have int values displayed (44205) that can only be formated as 01/01/1970 with what I'm used to use as php functions. Can you please help me ?

Thank you very much.

SimonAnnetts commented 3 years ago

Try this function to convert the integer (number of days since 30 Dec 1899) to a date with format YYYY-MM-DD

    //convert excel day since 30 dec 1899 to a date
    function convert_from_excel_date($edate) {
        if(!preg_match('/^[0-9]+$/',$edate)) return '0000-00-00';
        return date('Y-m-d', ($edate-25569)*86400);
    }