Freshworks named a Strong Performer in the Forrester Wave™: Enterprise Service Management, Q4 2021 Access Report

Start a new topic

How can a solve a NaN text in custom App


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:



    <script src=""></script>

    <script src=""></script>

    <script src="app.js"></script>

    <link rel="stylesheet" type="text/css" href="style.css">

    <link rel="stylesheet" type="text/css" href="">



    <div class="fw-widget-wrapper">

      <div class="logo"></div>

      <div id="apptext"></div>




1 Comment



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

Login or Signup to post a comment