rexcelexcel-formuladate-formatexcel-dates

How to convert number into date-time format in excel ( i have equivalent solution achieved in R)


enter image description here

Referring to the above screenshot, i'm trying to crawl data from Singapore Stock Exchange, which the web content is loaded dynamically from an API call returning json, example here

I'm having some problem with the dates, which is given as a number by the json. For example, 1575491760000 is supposed to be 2019-12-04 20:36:00GMT.

After some trial and error, i've figured solution using R:

as.POSIXct(1575491760000/1000, origin="1970-01-01", tz = 'GMT')  
# not sure why need to divide the number by 1000 here but i guess this is the way to make it work

and the above code does return "2019-12-04 20:36:00 GMT" in R.

However, my question is there a solution to the above conversion in Excel? I've tried a few different ways but none of them can deal with such long data scenario (date + time format). Appreciated if anyone can provide a specific solution!


Solution

  • Here's the Excel equivalent.

    =DATE(1970,1,1) + 1575491760000/(1000*60*60*24)
    # 12/4/19 20:36:00  with cell formatting set to   m/d/yy h:mm:ss
    

    Unix time increments one for every millisecond since 1/1/1970. Excel datetimes increment one for every day since 1/1/1900.

    So to convert from UNIX time to excel, divide by the number of milliseconds in a day (1000*60*60*24) and add to the date 1/1/70 (25569 under the hood in Excel.)