Arturo,
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
Arturo
Hi.
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;
$('#apptext').text(diff);
and this is HTML Template:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://static.freshdev.io/fdk/2.0/assets/fresh_client.js"></script>
<script src="app.js"></script>
<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">
</head>
<body>
<div class="fw-widget-wrapper">
<div class="logo"></div>
<div id="apptext"></div>
</div>
</body>
</html>