+ Reply to Thread
Results 1 to 19 of 19

13 digit date / time conversion specific to time zone

  1. #1
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    13 digit date / time conversion specific to time zone

    Hi and Merry Christmas
    I would like to convert 13 digit timestamp in A1 to date and time in B1 in yyyy-mm-dd hh:mm:ss.ms format taken into consideration my Athens Greece timezone offset.
    The DST (1 hour ahead) is done on last Sunday in March at 04:00, while the ST (1 hour behind) is done on last Sunday in October at 04:00.

    The proper conversion is offered at https://www.epochconverter.com/

    The formula I found online =(A1/86400000)+DATE(1970;1;1) is off in seconds / milli seconds and does not take the time zone into consideration.

    Your help is appreciated

    Examples from the site stated (They use AM / PM, while I would prefer 24 hour format)
    1570529351871
    GMT: Tuesday, October 8, 2019 10:09:11.871 AM
    My time zone: Tuesday, October 8, 2019 1:09:11.871 PM GMT+03:00 DST

    1572937323725
    GMT: Tuesday, November 5, 2019 7:02:03.725 AM
    My time zone: Tuesday, November 5, 2019 9:02:03.725 AM GMT+02:00

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,879

    Re: 13 digit date / time conversion specific to time zone

    Using helper columns

    timestamp in A1

    C1

    =INT(($A1/86400000+DATE(1970,1,1)))

    in D1 (Last Sunday in October)

    =EOMONTH(DATE(YEAR($C1),10,1),0)-MOD(WEEKDAY(EOMONTH(DATE(YEAR($C1),10,1),0),11),7)

    in E1 (Last Sunday in March)

    =EOMONTH(DATE(YEAR($C1),3,1),0)-MOD(WEEKDAY(EOMONTH(DATE(YEAR($C1),3,1),0),11),7)

    in B1

    =($A1/86400000+DATE(1970,1,1))+IF(AND(C1>=E1,C1<D1),TIME(3,0,0),TIME(2,0,0))
    Attached Files Attached Files
    Last edited by JohnTopley; 12-24-2021 at 09:34 AM.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: 13 digit date / time conversion specific to time zone

    =EOMONTH(DATE(YEAR($C1),3,1),0)-MOD(WEEKDAY(EOMONTH(DATE(YEAR($C1),3,1),0),11),7) gives #NUM!
    =EOMONTH(DATE(YEAR($C1),10,1),0)-MOD(WEEKDAY(EOMONTH(DATE(YEAR($C1),10,1),0),11),7) gives #NUM!

    my old version? (Using xls)

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,879

    Re: 13 digit date / time conversion specific to time zone

    I don't know what function exits in Excel 2002 but WEEKDAY may not!

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: 13 digit date / time conversion specific to time zone

    The 13 digit time stamp appears to represent milliseconds since midnight on the morning of 1 Jan 1970. I used this formula to convert to an Excel date/time serial number:

    =CONVERT(timestamp,"msec","day")+DATE(1970,1,1) -- I prefer the CONVERT() function here instead of timestamp/8640000 because it reminds me that the operation is really a unit conversion from milliseconds to days.

    Using the EOMONTH(....)-MOD(....) appears to be the part of John Topley's formula that handles the DST conversion. Looking at my copy of Excel 2002, the WEEKDAY() function is supported, but it only supports "return_type" values of 1, 2, or 3 (11 is not supported). Looking at the help file for the latest version (https://support.microsoft.com/en-us/...0-e404c190949a ) I cannot see what the difference is between 11 and 2 for the return_type -- they both seem to specify a Monday(1) to Sunday(7) week, so they look the same to me. Perhaps replacing the 11 in the WEEKDAY() function with 2 is all that is needed to make John's formula backwards compatible???

    Edit to add: In the OP, you noted an error in the seconds/milliseconds values that are returned. I know that this formula is not trying to account for leap seconds between 1970 and now, and I know there have been several leap seconds inserted during that time. Most of the time when this question is asked, the user is not worried about leap seconds, but your note that the seconds are in error makes me wonder if you are needing to account for leap seconds. Or maybe I am reading too much into the OP.
    Last edited by MrShorty; 12-24-2021 at 02:20 PM.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  6. #6
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: 13 digit date / time conversion specific to time zone

    1. Replacing 11 with 2 did the trick.
    2. Regarding the seconds / milliseconds error: According to epochconverter.com the last 3 digits of the, for example, 1570529351871 time stamp, represents milliseconds and according to that, it translates to 13:09:11.871 while the formula timestamp/86400000 (with noted adjustments) yields 13:09:12.912

    By the way, how do I maintain leading zero in milliseconds? If I use ".ms" I get 912 in this case BUT 24 instead of 024 in another timestamp. If I use ".mms" I get 024 BUT also 0912. (.000, .0ms, .#ms returned error).

  7. #7
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: 13 digit date / time conversion specific to time zone

    EDIT:
    I do not know if the error lies with epochconverter.com or with excel.
    Assuming the last 3 digits of the 13 digit timestamp represents milliseconds as the epochconverter seem to suggest, then truncating the timestamp to omit the last 3 digits and converting that to date / time should yield ZERO milliseconds. However, that is not the case because it yields 911 milliseconds! (=1570529351/86400+DATE(1970;1;1) --> 13:09:11.911)
    Last edited by drgkt; 12-24-2021 at 04:36 PM.

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: 13 digit date / time conversion specific to time zone

    Admittedly, I tested on LO Calc and Gnumeric rather than Excel, but I could not replicate your errors. When I enter 1570529351871 into the formula =number/86400000+DATE(1970,1,1) formatted as ss.000 (to show only the seconds portion), I get 11.871 as expected. If I enter any random up to 13 digit number into this, I always get the same three digits for the milliseconds portion (=RANDBETWEEN(0,1E12) generates the timestamp). I have a hard time believing that Excel would make an error in a calculation as basic as this. Perhaps someone else with Excel can check, but I expect that Excel's calculation should be correct.

  9. #9
    Valued Forum Contributor janmorris's Avatar
    Join Date
    07-24-2021
    Location
    Japan
    MS-Off Ver
    Google Sheets (& Mac 2021)
    Posts
    1,142

    Re: 13 digit date / time conversion specific to time zone

    @MrShorty

    I spent some time on this yesterday, and it is true, when excel converts from epoch to Unix time then there is a residual milliseconds, but if the Unix time is entered then it gives the correct epoch time.

    When the decimal time (the 42xxx number) is rounded either up or down from 5 to 4 decimals then it screws the seconds either way, so it not an option.

    After that i gave up as it seems excel wont play friendly when converting from epoch to Unix, even when there are no milliseconds involved excel creates them.

    The best i can think is that it is a rounding issue because all decimal time always has 5 decimal places, no further.

  10. #10
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: 13 digit date / time conversion specific to time zone

    Quote Originally Posted by MrShorty View Post
    ...When I enter 1570529351871 into the formula =number/86400000+DATE(1970,1,1) formatted as ss.000 (to show only the seconds portion), I get 11.871 as expected....
    I get 12.912 (in excel 2002 (xp)).

    So taken into consideration janmorris comments, where does this leave us?

  11. #11
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: 13 digit date / time conversion specific to time zone

    I'm not certain what errors @janmorris is referring to (unless it is floating point errors, but, in this case, an error of 40 milliseconds seems large for a floating point error). Ignoring the time zone change, there are really only two operations here: a division operation that would introduce a floating point error (no larger than 1E-9 days?? certainly no larger than 1 ms), and an addition operation that would propagate the floating point error but not make it worse.

    Debugging this probably involves looking carefully at those two operations to see where it is getting a 40 ms error.

    1570529351871/86400000=18177.4230540625 in my spreadsheet. What does your spreadsheet show? What do you get using a different calculator?
    18177.4230540625+25569=43746.4230540625 in my spreadsheet. What does your spreadsheet show? What do you get using a different calculator?

  12. #12
    Valued Forum Contributor janmorris's Avatar
    Join Date
    07-24-2021
    Location
    Japan
    MS-Off Ver
    Google Sheets (& Mac 2021)
    Posts
    1,142

    Re: 13 digit date / time conversion specific to time zone

    At https://www.epochconverter.com/
    if you enter in a 13 digit number, the last 3 digits are used directly as milliseconds.

    Screen Shot 2021-12-27 at 2.09.30 am.png

    in Excel, when you use a 13 digit number, the last 3 digits are not used directly as milliseconds, and when a 10 digit number is used, the formula division (inaccuracy) creates milliseconds.

    rounding of the decimal time can not fix this due to the limited number of decimal places used before it reads "00000"

    Screen Shot 2021-12-27 at 2.36.19 am.png

    so although it is possible to grab the left 10 digits to create the time, with the theory to then use some formula formatting magic to tag on the last 3 digits as milliseconds, this is not exactly practicable as excel rounds off the decimal time to 10 places, but uses the last 5.
    Attached Files Attached Files

  13. #13
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: 13 digit date / time conversion specific to time zone

    I see an error in number format coding. In your file, your number format code is "dd/mm/yy hh:mm:ss\.ms". In Excel, "ms" does not mean "milliseconds". "m" means "minute" (or month, in the date portion) and "s" means seconds, so, the format code "...:ss\.ms" means "show the seconds (with leading 0 to make two digits), then show a decimal point, then show the minute again, followed by the second again. Looking at all of the examples in your picture, and notice that, in all of your examples, what we are calling "milliseconds" is really just repeating the minutes and seconds shown earlier in the display.

    The correct code for "fractions of a second up to milliseconds" is "...:ss.000" or similar https://support.microsoft.com/en-us/...7-9c9354dd99f5 . I expect if you will try this format code, you will see that Excel is correctly calculating a serial number with 871 milliseconds in the C2.

  14. #14
    Valued Forum Contributor janmorris's Avatar
    Join Date
    07-24-2021
    Location
    Japan
    MS-Off Ver
    Google Sheets (& Mac 2021)
    Posts
    1,142

    Re: 13 digit date / time conversion specific to time zone

    DOH!

    haha.

    yes the .000 for milliseconds worked perfectly, awesome!

  15. #15
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: 13 digit date / time conversion specific to time zone

    Unfortunately my version won't accept this format yyyy-mm-dd hh:mm:ss.000.
    I do understand, however: I am getting 12 seconds because it is rounding off 11.871 milliseconds.
    So .ms translates to m=9 minutes and s=12 seconds thus the fake impression of 12 seconds and 912 milliseconds!!!!!

    THANK YOU for making this clear.

    Is there something I can do? (since the above format is not accepted).
    Last edited by drgkt; 12-27-2021 at 03:18 AM.

  16. #16
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: 13 digit date / time conversion specific to time zone

    My copy of 2002 has no trouble with that number format code, so I'm not sure what to recommend.

    Here's my file, if it helps.
    Attached Files Attached Files

  17. #17
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: 13 digit date / time conversion specific to time zone

    MrShorty !!!

    So simple, I would have not found it if I did not download your file in the previous post!
    It takes the format ...ss,000 BUT NOT the format ...ss.000 (depending on locale, I guess)

    Thanks everybody!
    Last edited by drgkt; 12-30-2021 at 12:21 PM.

  18. #18
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: 13 digit date / time conversion specific to time zone

    Glad you got it to work. This forum is international (even if it's primary language is English), but I don't know how to make it and its posters (including myself) more internationally aware. We have several rules, perhaps another one that insists that posters include in their post or a signature their preferred thousands, decimal, and list separators?

  19. #19
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: 13 digit date / time conversion specific to time zone

    Mechanically, I replaced coma with semicolon in my formulas, but this never occurred to me!

    I 'll vote for that!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to do Date + Time Zone conversion in Excel
    By Ankit_Kumar in forum Excel General
    Replies: 6
    Last Post: 03-12-2020, 02:07 AM
  2. How to convert from indian time zone to US time zone
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-18-2018, 05:42 AM
  3. How to do Date + Time Zone conversion in Excel??
    By mailtojsb in forum Excel General
    Replies: 9
    Last Post: 08-05-2016, 08:35 PM
  4. Time Zone Conversion
    By Krix in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-07-2014, 11:41 AM
  5. Time Zone Conversion Table
    By naven_sg in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-09-2012, 08:24 AM
  6. Date and time conversion to another time zone
    By RUBEN PARRAS in forum Excel General
    Replies: 1
    Last Post: 05-21-2012, 09:03 PM
  7. Time Zone Conversion Button
    By vamshi57 in forum Excel General
    Replies: 2
    Last Post: 01-22-2011, 04:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1