## date time conversion

By : abbas
Source: Stackoverflow.com
Question!

I have 40241 as a date value. Which format is this in?

I think it is in seconds past midnight. But I need a formula so that I can work out manually and verify!!

Thanks

By : abbas

Excel stores dates in an interesting way. I've had this crop up on me too but I never had to move outside Excel so I could just use the format function in Excel.

By : Skurmedel

Excel saves the date as an integer for the number of days since Jan 1st, 1900

Note: there is a bug in excel so you do the conversion and subtract one. If you see a decimal after it is the time.

Here is some java code to convert it if you want to verify it:

``````public static Date ExcelDateParse(int ExcelDate){
Date result = null;
try{
GregorianCalendar gc = new GregorianCalendar(1900, Calendar.JANUARY, 1);
result = gc.getTime();
} catch(RuntimeException e1) {}
return result;
}
``````
By : Dave

I condensed the apache solution for the date without time ( https://svn.apache.org/repos/asf/poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java )

``````  public static Date parseExcelDate(double date) {
int wholeDays = (int) Math.floor(date);
Calendar calendar = new GregorianCalendar();
int startYear = 1900;
``` By : Bruno Eberhard ```
``` This video can help you solving your question :) By: admin ```
``` Related Questions Percentage of Tax Year Remaining C# to Excel set custom date display and value Excel: date formatting (adsbygoogle = window.adsbygoogle || []).push({}); Excel: Compare DateTime to Date Extract badly formatted date from a mixed string and convert to YYYY-MM-DD Using Python's xlrd module to find column with most dates Finding min date from datetime in excel Comparing a column of string date-times with Now( Set 00:00 as the last timestamp in Excel How to convert this Text field into a DATE field using DAX formulas? Calculating exact fraction of months during period Complex date manipulation Loop for difference in dates between two columns Counting numbers per hour between a start and end time Date and format functions Getting a year from a 4-digit number in Excel 2013 Separate date and time in Excel Covert YYYY-MMM-DD into DD/M/YYYY in excel Cell date format in excel showing datetime ```
``` ```
``` About Us    Contact Us    Legal    feedback    Copyright © 2015 - All Rights Reserved - www.4answered.com 'undefined'=== typeof _trfq || (window._trfq = []);'undefined'=== typeof _trfd && (window._trfd=[]),_trfd.push({'tccl.baseHost':'secureserver.net'}),_trfd.push({'ap':'cpsh'},{'server':'p3plcpnl0831'}) // Monitoring performance to make your website faster. If you want to opt-out, please contact web hosting support.```