Question

My client receives a spreadsheet with a number of columns, one being a "date". Only the date turns out to be formatted as Date(1292291582263-0700) (a JSON date it seems).

I need to convert and work with this JSON date in MM/DD/YYYY format, elsewhere in this spreadsheet's code (VBA).

Does anyone know how to parse and convert this JSON date format into a MM/DD/YYYY format? I have read lots of solutions on SO that are in Javascript, C#, or ASP.NET, etc but all I have to work with is Excel 2010 and VBA code for this project. Is there way to arrive at a readable format as I need?

Was it helpful?

Solution

Millisecond Epoch time with a +/- offset?

Const test = "1292291582263-0700"

Dim dt As String: dt = Left$(test, 13)
Dim off As String: off = Mid$(test, 14)

Dim d As Date: d = DateAdd("s", CCur(dt) / 1000, "01/01/1970")
Debug.Print d
<<< 14/12/2010 01:53:02 

d = DateAdd("h", Left$(off, 3), d)
d = DateAdd("n", Right$(off, 2), d)
Debug.Print d
<<< 13/12/2010 18:53:02 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top