How to represent a DateTime in Excel
The underlying data type of a datetime in Excel is a 64-bit floating point number where the length of a day equals 1
and 1st Jan 1900 00:00
equals 1
. So 11th June 2009 17:30
is about 39975.72917
.
If a cell contains a numeric value such as this, it can be converted to a datetime simply by applying a datetime format to the cell.
So, if you can convert your datetimes to numbers using the above formula, output them to the relevant cells and then set the cell formats to the appropriate datetime format, e.g. yyyy-mm-dd hh:mm:ss
, then it should be possible to achieve what you want.
Also Stefan de Bruijn has pointed out that there is a bug in Excel in that it incorrectly assumes 1900 is a leap year so you need to take that into account when making your calculations (Wikipedia).
If, like me, you can't find a datetime under date or time in the format dialog, you should be able to find it in 'Custom'.
I just selected 'dd/mm/yyyy hh:mm' from 'Custom' and am happy with the results.
You can do the following:
=Datevalue(text)+timevalue(text)
.
Go into different types of date formats and choose:
dd-mm-yyyy mm:ss am/pm
.