I have written a function but it does not give an actual O/P...
public int date(Object O) { if (O instanceof Date) { Date d1 = (Date) O;
The right algorithm is already implemented in Apache POI. Take a look at class org.apache.poi.ss.usermodel.DateUtil.
Also this description could be useful: http://support.microsoft.com/kb/214094/en-us