Does anyone know how to convert an Excel date to a correct Unix timestamp?
相关问题
- Excel sunburst chart: Some labels missing
- Error handling only works once
- Excel formula in VBA code
- Excel VBA run time error 450 from referencing a ra
- DoCmd.TransferSpreadsheet is not recognizing works
相关文章
- Get column data by Column name and sheet name
- programmatically excel cells to be auto fit width
- Unregister a XLL in Excel (VBA)
- How to prevent excel from truncating numbers in a
- numeric up down control in vba
- Declare a Range relative to the Active Cell with V
- What's the easiest way to create an Excel tabl
- How to create a hyperlink to a different Excel she
I had an old Excel database with "human-readable" dates, like 2010.03.28 20:12:30 Theese dates were in UTC+1 (CET) and needed to convert it to epoch time.
I used the =(A4-DATE(1970;1;1))*86400-3600 formula to convert the dates to epoch time from the A column to B column values. Check your timezone offset and make a math with it. 1 hour is 3600 seconds.
The only thing why i write here an anwser, you can see that this topic is more than 5 years old is that i use the new Excel versions and also red posts in this topic, but they're incorrect. The DATE(1970;1;1). Here the 1970 and the January needs to be separated with ; and not with ,
If you're also experiencing this issue, hope it helps you. Have a nice day :)
Non of these worked for me... when I converted the timestamp back it's 4 years off.
This worked perfectly:
=(A2-DATE(1970,1,1))*86400
Credit goes to: Filip Czaja http://fczaja.blogspot.ca
Original Post: http://fczaja.blogspot.ca/2011/06/convert-excel-date-into-timestamp.html
You're apparently off by one day, exactly 86400 seconds. Use the number 2209161600 Not the number 2209075200 If you Google the two numbers, you'll find support for the above. I tried your formula but was always coming up 1 day different from my server. It's not obvious from the unix timestamp unless you think in unix instead of human time ;-) but if you double check then you'll see this might be correct.
Here is a mapping for reference, assuming UTC for spreadsheet systems like Microsoft Excel:
* “Jan Zero, 1900” is 1899/12/31; see the Bug section below. † Excel 2011 for Mac (and older) use the 1904 date system.
As I often use
awk
to process CSV and space-delimited content, I developed a way to convert UNIX epoch to timezone/DST-appropriate Excel date format:I used
echo
for this example, but you can pipe a file where the first column (for the first cell in .csv format, call it asawk -F,
) is a UNIX epoch. Alter$1
to represent your desired column/cell number or use a variable instead.This makes a system call to
date
. If you will reliably have the GNU version, you can remove the2>/dev/null || date … +%%z
and the second, $1
. Given how common GNU is, I wouldn't recommend assuming BSD's version.The
getline
reads the time zone offset outputted bydate +%z
intotz
, which is then translated intohours
. The format will be like-0700
(PDT) or+0530
(IST), so the first substring extracted is07
or05
, the second is00
or30
(then divided by 60 to be expressed in hours), and the third use oftz
sees whether our offset is negative and altershours
if needed.The formula given in all of the other answers on this page is used to set
excel
, with the addition of the daylight-savings-aware time zone adjustment ashours/24
.If you're on an older version of Excel for Mac, you'll need to use
24107
in place of25569
(see the mapping above).To convert any arbitrary non-epoch time to Excel-friendly times with GNU date:
This is basically the same code, but the
date -d
no longer has an@
to represent unix epoch (given how capable the string parser is, I'm actually surprised the@
is mandatory; what other date format has 9-10 digits?) and it's now asked for two outputs: the epoch and the time zone offset. You could therefore use e.g.@1234567890
as an input.Bug
Lotus 1-2-3 (the original spreadsheet software) intentionally treated 1900 as a leap year despite the fact that it was not (this reduced the codebase at a time when every byte counted). Microsoft Excel retained this bug for compatibility, skipping day 60 (the fictitious 1900/02/29), retaining Lotus 1-2-3's mapping of day 59 to 1900/02/28. LibreOffice instead assigned day 60 to 1900/02/28 and pushed all previous days back one.
Any date before 1900/03/01 could be as much as a day off:
Excel doesn't acknowledge negative dates and has a special definition of the Zeroth of January (1899/12/31) for day zero. Internally, Excel does indeed handle negative dates (they're just numbers after all), but it displays them as numbers since it doesn't know how to display them as dates (nor can it convert older dates into negative numbers). Feb 29 1900, a day that never happened, is recognized by Excel but not LibreOffice.