0

There's a graph I'm using from CanvasJS which I've inserted data into from our SQL Server. I'm having an issue though where for one of the axis, I need it to show as a date. CanvasJS comes with the function to be able to set the value type for the axis between two settings, 'dateTime' and 'number'.

The format CanvasJS is using is a 13 digit string, ex. "1088620200000". When using https://timestamp.online/ to check what it converts to, it looks like all the examples have 3 extra 0's added to the end of it, because when you take off those extra 0's it translates to June 30th, 2004 which is correct from the example.

I've used this line in my query to convert my datestamps to strings. Originally, I had the start date as a suggested default of "1990-1-1", but saw it was adding incorrectly and I adjusted it to give almost the right dates.

CAST(CAST(DATEDIFF(minute, '1990-5-28 00:00', ##customOrderMetrics.METRIC_DATE) AS BIGINT) AS VARCHAR)+'00' AS METRIC_DATE

My issue here is that it seems to be converting correctly but does so in a weird way. It's adding uneven amounts to the days and I'd like it to just jump 24 hours or 1 day. So, I have 4 rows coming from the query and they look like this.

  1. 1/4/2021, 8:00:00 AM - 1609776000

  2. 1/6/2021, 12:00:00 AM - 1609920000

  3. 1/7/2021, 4:00:00 PM - 1610064000

  4. 1/9/2021, 8:00:00 AM - 1610208000

This was really tough to explain, but I hope it makes some sense. Really would appreciate any help and hope I'm not missing something simple here. Thanks in advance.

1 Answer 1

1

The reason for the extra 0's is that javascript timestamps use miliseconds. I think you overthinking this. Just get a UNIX timestamp from your database like

SELECT UNIX_TIMESTAMP(your_date) * 1000

and put that number into the datapoints object of your canvas.

Sign up to request clarification or add additional context in comments.

2 Comments

Ah, okay. Makes sense. Definitely felt like I was overthinking a little bit. Looks like the UNIX timestamp doesn't work in SQL Server. Any alternatives?
Worked perfectly. Really just needed to know the name of the style of timestamp. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.