Excel Date for Unix Timestamp

Does anyone know how to convert an Excel date to the correct Unix timestamp?

+72
excel
Nov 09 '09 at 20:21
source share
8 answers

Without them, they worked for me ... when I converted the timestamp back to 4 years.

This worked perfectly: =(A2-DATE(1970,1,1))*86400

Credit goes: Filip Czaja http://fczaja.blogspot.ca

Original post: http://fczaja.blogspot.ca/2011/06/convert-excel-date-into-timestamp.html

+88
Jun 21 '12 at 14:57
source share

Windows and Mac Excel (2011):

 Unix Timestamp = (Excel Timestamp - 25569) * 86400 Excel Timestamp = (Unix Timestamp / 86400) + 25569 

MAC OS X (2007):

 Unix Timestamp = (Excel Timestamp - 24107) * 86400 Excel Timestamp = (Unix Timestamp / 86400) + 24107 

Reference:

 86400 = Seconds in a day 25569 = Days between 1970/01/01 and 1900/01/01 (min date in Windows Excel) 24107 = Days between 1970/01/01 and 1904/01/02 (min date in Mac Excel 2007) 
+55
May 27 '11 at 16:10
source share

Assuming the date in Excel is in cell A1, formatted as Date, and the Unix timestamp should be in cell A2, formatted as a number, the formula in A2 should be:

= (A1 * 86400) - 2209075200

Where:

86400 - number of seconds per day 2209075200 - this is the number of seconds between 1900-01-01 and 1970-01-01, which are base dates for Excel and Unix timestamps.

The above is true for Windows. On Mac, the base date in Excel is 1904-01-01, and the number of seconds should be adjusted to: 2082844800

+11
Nov 09 '09 at 20:46
source share

Here is the mapping for the link, assuming UTC for spreadsheet systems such as Microsoft Excel:

  Unix Excel Mac Excel Human Date Human Time Excel Epoch -2209075200 -1462 0 1900/01/00* 00:00:00 (local) Excel ≤ 2011 Mac† -2082758400 0 1462 1904/12/31 00:00:00 (local) Unix Epoch 0 24107 25569 1970/01/01 00:00:00 UTC Example Below 1234567890 38395.6 39857.6 2009/02/13 23:31:30 UTC Signed Int Max 2147483648 51886 50424 2038/01/19 03:14:08 UTC One Second 1 0.0000115740… — 00:00:01 One Hour 3600 0.0416666666… ― 01:00:00 One Day 86400 1 1 ― 24:00:00 

<sub> * "Jan Zero, 1900" - 1899/12/31; see the Error section below. Excel 2011 for Mac (and later) uses the 1904 date system .

As I often use awk to handle CSV and space-delimited content, I developed a way to convert the UNIX era to a timezone / DST local Excel date format:

 echo 1234567890 |awk '{ # tries GNU date, tries BSD date on failure cmd = sprintf("date -d@%d +%%z 2>/dev/null || date -jf %%s %d +%%z", $1, $1) cmd |getline tz # read in time-specific offset hours = substr(tz, 2, 2) + substr(tz, 4) / 60 # hours + minutes (hi, India) if (tz ~ /^-/) hours *= -1 # offset direction (east/west) excel = $1/86400 + hours/24 + 25569 # as days, plus offset printf "%.9f\n", excel }' 

I used echo for this example, but you can pass the file where the first column (for the first cell in .csv format, called as awk -F, ) is the UNIX era. Alter $1 to indicate the desired column / cell number or use a variable instead.

This makes the date system call. If you will have a reliable version of GNU, you can remove 2>/dev/null || date … +%%z 2>/dev/null || date … +%%z and the second , $1 . Given how common GNU is, I would not recommend the BSD version.

getline reads the timezone offset displayed by date +%z in tz , which is then converted to hours . The format will look like -0700 ( PDT ) or +0530 ( IST ), so the first substring received is 07 or 05 , the second is 00 or 30 (then divided by 60, expressed in hours), and the third use of tz shows whether our offset negative and changes the hours if necessary.

The formula given in all the other answers on this page is used to set excel with the addition of the time zone setting for daylight as hours/24 .

If you are using an older version of Excel for Mac, you need to use 24107 instead of 25569 (see the comparison above).

To convert any arbitrary time without time to a time convenient for Excel with a GNU date:

 echo "last thursday" |awk '{ cmd = sprintf("date -d \"%s\" +\"%%s %%z\"", $0) cmd |getline hours = substr($2, 2, 2) + substr($2, 4) / 60 if ($2 ~ /^-/) hours *= -1 excel = $1/86400 + hours/24 + 25569 printf "%.9f\n", excel }' 

This is basically the same code, but date -d no longer has @ to represent unix epoch (considering how capable the parser is, I'm really surprised that @ is mandatory; what other date format has 9-10 digits?), And now he has requested two exits: era and time zone offset. Therefore, you can use, for example, @1234567890 as an input.

Mistake

Lotus 1-2-3 (the source software for the spreadsheet) intentionally treated 1900 as a leap year , despite the fact that it was not (this reduced the code base at the time when each byte was counted). Microsoft Excel saved this error for compatibility by skipping day 60 (dummy 1900/02/29) while maintaining the Lotus 1-2-3 display day 59-1900 / 02/28. LibreOffice instead set a day from 60 to 1900/02/28 and clicked all the previous days ago.

Any date before 1900/03/01 can be a day off:

 Day Excel LibreOffice -11899/12/29 0 1900/01/00* 1899/12/30 1 1900/01/01 1899/12/31 2 1900/01/02 1900/01/0159 1900/02/28 1900/02/27 60 1900/02/29(!) 1900/02/28 61 1900/03/01 1900/03/01 

Excel does not recognize negative dates and has a special definition of Zeroth of January for day zero. Internally, Excel does handle negative dates (they are just numbers after all), but it does not know how to display them as dates (nor can it convert older dates to negative numbers). February 29, 1900, which never happened, is recognized by Excel, but not LibreOffice.

+6
Sep 15 '15 at 5:01
source share

You are obviously disconnected for one day, exactly 86400 seconds. Use the number 2209161600 Not the number 2209075200 If you are Google two numbers, you will find support above. I tried your formula, but was always 1 day different from my server. This is not obvious from unix timestamp unless you think in unix instead of human time ;-), but if you double check it, you will see that it might be right.

+2
Mar 23 2018-11-23T00:
source share

Since my corrections to the above were rejected (did any of you really try?), Here is what you really need to do for this to work:

Windows (and Mac Office 2011+):

  • Unix Timestamp = (Excel Timestamp - 25569) * 86400
  • Excel (Unix Timestamp / 86400) + 25569 = (Unix Timestamp / 86400) + 25569

MAC OS X (pre Office 2011):

  • Unix Timestamp = (Excel Timestamp - 24107) * 86400
  • Excel (Unix Timestamp / 86400) + 24107 = (Unix Timestamp / 86400) + 24107
+2
Feb 13 '13 at 16:11
source share

None of the current answers worked for me, because my data was in this format from the unix side:

2016-02-02 19:21:42 UTC

I needed to convert this to Epoch so that I could reference other data that had timestamps.

  • Create a new column for the date part and analyze using this formula

     =DATEVALUE(MID(A2,6,2) & "/" & MID(A2,9,2) & "/" & MID(A2,1,4)) 
  • As another Grendler already mentioned, create another column

     =(B2-DATE(1970,1,1))*86400 
  • Create another time-added column to get the total number of seconds:

     =(VALUE(MID(A2,12,2))*60*60+VALUE(MID(A2,15,2))*60+VALUE(MID(A2,18,2))) 
  • Create the last column that just adds the last two columns together:

     =C2+D2 
0
Feb 03 '16 at 20:17
source share

Here is my final answer to this question.

It is also obvious that the javascript new Date(year, month, day) constructor does not account for leap seconds as well.

 // Parses an Excel Date ("serial") into a // corresponding javascript Date in UTC+0 timezone. // // Doesn't account for leap seconds. // Therefore is not 100% correct. // But will do, I guess, since we're // not doing rocket science here. // // https://www.pcworld.com/article/3063622/software/mastering-excel-date-time-serial-numbers-networkdays-datevalue-and-more.html // "If you need to calculate dates in your spreadsheets, // Excel uses its own unique system, which it calls Serial Numbers". // lib.parseExcelDate = function (excelSerialDate) { // "Excel serial date" is just // the count of days since `01/01/1900` // (seems that it may be even fractional). // // The count of days elapsed // since `01/01/1900` (Excel epoch) // till `01/01/1970` (Unix epoch). // Accounts for leap years // (19 of them, yielding 19 extra days). const daysBeforeUnixEpoch = 70 * 365 + 19; // An hour, approximately, because a minute // may be longer than 60 seconds, see "leap seconds". const hour = 60 * 60 * 1000; // "In the 1900 system, the serial number 1 represents January 1, 1900, 12:00:00 am // while the number 0 represents the fictitious date January 0, 1900". // These extra 12 hours are a hack to make things // a little bit less weird when rendering parsed dates. // Eg if a date `Jan 1st, 2017` gets parsed as // `Jan 1st, 2017, 00:00 UTC` then when displayed in the US // it would show up as `Dec 31st, 2016, 19:00 UTC-05` (Austin, Texas). // That would be weird for a website user. // Therefore this extra 12-hour padding is added // to compensate for the most weird cases like this // (doesn't solve all of them, but most of them). // And if you ask what about -12/+12 border then // the answer is people there are already accustomed // to the weird time behaviour when their neighbours // may have completely different date than they do. // // `Math.round()` rounds all time fractions // smaller than a millisecond (eg nanoseconds) // but it unlikely that an Excel serial date // is gonna contain even seconds. // return new Date(Math.round((excelSerialDate - daysBeforeUnixEpoch) * 24 * hour) + 12 * hour); }; 
0
Sep 07 '17 at 15:06
source share



All Articles