cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Post Patron
Post Patron

Convert json DateTime format

Hi,

 

How do I convert a column containing a date and time in the json format to DateTime. My dates are like this /Date(1457355600000)

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

I was referring to change your query name so that your table name in the data model doesn't have the GUID and such in it and ? and such.


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

12 REPLIES 12
Highlighted
Super User IV
Super User IV

My understanding of JSON Dates is that it is the number of milliseconds from a reference date of 1/1/1970. Therefore, I would strip out all the text characters, if you need assistance with that, let me know but you could do it with a MID that grabs the first character after the ( and grabs the number of characters up until the ). Make sure it is a number format and then you can use the following DAX:

 

Date = DATE(1970,1,1) + [JSONDate]/1000/86400

Basically, divide by 1,000 to get seconds and then by 86,400, the number of seconds in a day (you could just divide by 864,000. This gives you the number of days since 1/1/1970 and then you just add that to a date of 1/1/1970. I got back "3/7/2016 1:00:00 PM"


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Highlighted

Hi,

 

Thanks for your assistance. I'm having a bit of trouble with this. I have stripped out the text using extract. I am left with values such as 453808709000. When I change this column to a decimal number I get 4.53809E+11.

 

I perform the following DAX formula -> Temp1 = DATE(1970,1,1) + [Column1.DutyTimeFrom]/1000/86400. 

[Column1.DutyTimeFrom] contains 4.53809E+11.

 

i get the following error message -> The value for 'Column1.DutyTimeFrom' cannot be determined. Either 'Column1.DutyTimeFrom' doesn't exist, or there is no current row for a column named 'Column1.DutyTimeFrom'.

 

Highlighted

@android1 - Can you post a screen shot of your data model so that I can see your columns? The error indicates that it can't find [Column1.DutyTimeFrom]. This could be because you need to put the table name in front of it or that there is a typo or something.


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Highlighted

JSon Date Conversion.png

Highlighted

Hmm, I creatd a column in a test model called Column1.DutyTimeFrom and was able to interact with it no problem. Only thing I can think of is that perhaps it doesn't really like your table naming convention. Can you right click it and rename it to something simple like "ClickData" and see if that resolves the issue?


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Highlighted

Hi,

 

Still no luck. Same error message appearing. I've attached a pic of my Query, showing the colun & data type.JSon Date Conversion 2.jpg

Highlighted

I was referring to change your query name so that your table name in the data model doesn't have the GUID and such in it and ? and such.


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Highlighted

Hi,

 

Still no luck. Query name changed & same error message. One of those weird ones it seems.

Highlighted

Hi,

 

What you have told me to do is correct, something else is throwing it off. I'll mark your answer as the solution.

Thanks for your help.

 

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Community Conference

Microsoft Power Platform Communities

Check out the Winners!

secondImage

Create an end-to-end data and analytics solution

Learn how Power BI works with the latest Azure data and analytics innovations at the digital event with Microsoft CEO Satya Nadella.

Top Solution Authors
Top Kudoed Authors