I have a date value (10/11/2012) in my excel sheet in format (mm/dd/yyyy i.e. US format). I have to validate this date to confirm it is a valid date. How do I do that?
POI issue tracker is not a place to ask usage questions, please ask on the @poi-user mailing list. The answer depends on how you store date values in Excel: as date or as string. If the value is stored as a date then use cell.getDateCellValue() to get value of cell as a java.util.Date. In this case there is nothing to validate. If the vaue is string then it is up to you how to check: you can fetch the string value and check it against a regex or write a validator yourself. the code might look as follows: switch(cell.getCellType()){ case Cell.CELL_TYPE_NUMERIC: date = cell.getDateCellValue(); break; case Cell.CELL_TYPE_STRING: String sval = cell.getStringCellValue(); if(sval.matches("\\d\\d/\\d\\d/\\d\\d\\d\\d")){ // dd/mm/yyyy // parse as a date } } note that internally Excel stores dates as numbers, that is why the first case is Cell.CELL_TYPE_NUMERIC' Yegor