This is my first custom App. I'm trying to display a simple calculation.
I took ticket creation time, then substract it from present time (now), and want to display the result.
That result always displays: "NaN".
What do you recommend?
This is part of code:
const right_now = new Date();
const diff = (right_now - data.ticket.created_at)/1000;
and this is HTML Template:
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="https://static.freshdev.io/fdk/2.0/assets/freshservice.css">
The value of data.ticket.created_at is a datetime ISO string. You cannot subtract a string from the Date object instance, thats why the NaN.
You can get a date object for the created_at by doing new Date(data.ticket.created_at) and find the diff after. Finding diff of dates in JS could be a little tricky depending on what exactly you need. Here's a Stackoverflow thread on Date diff to get you started