Question : Does anyone know xls2csv and why it formats dates exactly 4 years and one day in the future? (also mathematical question)

You're all probably going to say I'm using the wrong software, but it fits my needs perfectly. I found a set of command line DOS tools which convert all manner of files to plain text. Great for importing Excel files into mySQL.

xls2.csv is extremely quick and does the job marvellously for me in batch files -- except for dates. I format dates with the command line option -f %Y-%m-%d  or even %d-%b-%y but each date comes out four years and one day ahead of the date I input. So curiously enough the earliest date it will process is 31 December 1965 (returns 01-01-1970) but it DOES get leap years right (28 Feb 1968 returns 29 Feb 1972).

Anyway, I'm asking here mainly because there's so little information on it that I can find (I guess the company went out business, but it is freeware), and also if anyone knows of a *mathematical* reason why it might be doing this so I could reliably correct it with code after the data has been imported. I'm tempted to subtract four years and one day from the returned result, but that might not be correct if the result has been counted in seconds.

Anyway, I'll attach 500 points to this one, because I have a feeling no one will know! (and I won't be awarding points to anyone who tells me to use a PHP module -- DOS batch files only on the server in question!)

Answer : Does anyone know xls2csv and why it formats dates exactly 4 years and one day in the future? (also mathematical question)

The reason is because .xls supports two different date formats: http://support.microsoft.com/kb/180162
(which also explains the reasoning why - since Excel is also produced, and older Macs had an epoch starting in 1904).
Since the adjustment is done in terms of days, and always by a fixed amount, you are correct in that you can subtract the same amount, provided the spreadsheet was using the 1904 date system. Since it appears your xls2csv isn't recognising which date format the spreadsheet is in, it might be the case that you get a spreadsheet in the 1900 format, in which case the date the xls2csv produces will be correct, and then you will be wrong in subtracting from it. It might be an idea to write an Excel script to change the xls files into the right date system first, or find a different xls2csv converter.
Random Solutions  
 
programming4us programming4us