Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DATE() function throws exception if given number of days #3

Open
markbirbeck opened this issue Nov 23, 2010 · 2 comments
Open

DATE() function throws exception if given number of days #3

markbirbeck opened this issue Nov 23, 2010 · 2 comments

Comments

@markbirbeck
Copy link
Member

Excel spreadsheets store dates as the number of days since January 1st, 1900. If a CSV file hasn't been correctly exported then this can manifest itself as a value like '40337'. It would be good to convert this automatically to the correct date.

@markbirbeck
Copy link
Member Author

More information on this format is available here:

http://www.cpearson.com/excel/datetime.htm

@Christian-B
Copy link

In E_Date class use the following:
public static Date parse(String date) throws ParseException {
try {
return DATE_TIME.parse(date).toDate();
} catch (Exception e){
//Ok now lets try it as a day in numbers.
int days = Integer.parseInt(date);
if (days > 60){
days--; //Fix the Excell bug of counting none existing 29 Febuary 1900 as day 60
}
GregorianCalendar calendar = new GregorianCalendar (1900, 0, days, 0 , 0, 0);
return calendar.getTime();
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants