title: Compare MySQL Timestamp with NodeJS
body: <p>I am trying to compare timestamp of MySQL with current timestamp on NodeJS.</p>
  
  <p>I am adding the timestamp in this way to MySQL:</p>
  
  <pre><code>var updateQuery = "UPDATE user SET last_pub = ? + INTERVAL 5 HOUR WHERE uid = '" + uid + "'";
  
  var mysqlTimestamp = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
  return req.dbConnection.query(updateQuery, mysqlTimestamp) // I call this to run the query
  </code></pre>
  
  <p>I compare it in this way:</p>
  
  <pre><code>function checkTime() {
   return req.dbConnection.query(checkUser)
     .then(([rows, fields]) =&gt; {
              if (rows != "") {
                  var rowResult = JSON.parse(JSON.stringify(rows[0]));
                  var mysqlTimestamp = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
                  console.log(rowResult.last_pub)
                  console.log(mysqlTimestamp)
                  if (rowResult.last_pub &gt; mysqlTimestamp) {
                      var dict = {}
                      dict.response = "wait"
                      console.log("hour not passed");
                      req.dbConnection.end()
                      console.log(JSON.stringify({"status": 200, "error": null, "response": dict}))
                      return res.send(JSON.stringify({"status": 200, "error": null, "response": dict}));
                  }
                  else {
                      console.log("done")
                  }
              }
              else {
                  console.log("Error - user not exist")
              }
          }).catch((error) =&gt; console.log(error));
  }
  </code></pre>
  
  <p>When I try to print the two timestamp I got this two:</p>
  
  <pre><code>2019-01-03T04:02:00.000Z (MySQL result)
  2019-01-03 00:02:07 +01:00 (moment result)
  </code></pre>
  
  <p>The problem is that the hour is everytimes "hour not passed" even if the last_pub is &lt; of mysqlTimestamp</p>
  
  <p>I have done some test and when I do the check with rowResult.last_pub > mysqlTimestamp its not checking the hour but its checking the day. Because If I change the hour its always "hour not passed" but If I change the day it print "done". I have to do the check with hour too</p>
  
  <p>N. = All my timestamp is in UTC (System and MySQL) and the field’s type of time where we are working is set to TIMESTAMP </p>