Q:

compare datetime in postgresql

For reseting password, I am checking if token is expires which is valid for an hour.
To achieve this, I save 'inOneHour' datetime in 'resetPasswordExpires' column (db) and compare with 'now' datetime on reset password request. But it fails.
moment.js
export const now = moment().format();
export const inOneHour = moment()
  .add(1, 'hours')
  .format();

postgresql
table.datetime('resetPasswordExpires', { useTz: false });

auth.js
exports.forgotPassword = (req, res) => {
const { username, email, inOneHour } = req.body;

  return knex('users')
    .where({ username, email })
    .first()
    .then(async user => {
        ...
        return knex('users')
          .where({ username })
          .first()
          .update({
            resetPasswordToken: token,
            resetPasswordExpires: inOneHour,
          })
          .then(() => {
            ...
    });
};

exports.resetPasswordWithToken = (req, res) => {
  const { newPassword, now } = req.body;
  const { token } = req.params;

  knex('users')
    .where({ resetPasswordToken: token })
    .andWhere('resetPasswordExpires', '>', now)
    .first()
    .then(user => {
      if (user) {
        const id = user.id;
        return setPassword(id, newPassword)
          .then(() =>
            knex('users')
              .where({
                id,
              })
              .first()
              .update({
                resetPasswordToken: null,
                resetPasswordExpires: null,
              }),
          )
          .then(() => res.status(200).json())
          .catch(err => res.status(409).json(err));
      }
      return res.status(409).json('Access token is invalid or has expired');
    })
    .catch(err => res.status(409).json(err));
};

when moment.format()
// passing datetime to update 'resetPasswordExpires' column
console.log(inOneHour) // 2019-07-19T01:19:16+09:00

// 'resetPasswordExpires' value after updated
console.log(resetPasswordExpires) // 2019-07-18T16:19:16.000Z

// passing datetime to compare
console.log(now) // 2019-07-19T00:20:02+09:00

when moment.format('MMMM DD YYYY, HH:mm:ss')
console.log(inOneHour) // July 19 2019, 01:16:17
console.log(resetPasswordExpires) // 2019-07-18T16:16:17.000Z
console.log(now) // July 19 2019, 00:17:38

Two different datetime formats are saved in the same format in database.
Even When I set the 'resetPasswordExpired' datetime type with Timezone and use moment.format(), It still doesn't work.
How can I work around this ?
when moment.format() && table.datetime('resetPasswordExpires');
console.log(inOneHour) // July 19 2019, 01:16:17
console.log(resetPasswordExpires) // 2019-07-18T16:16:17.000Z
console.log(now) // July 19 2019, 00:17:38

A:

I reopen my laptop. somehow this code is working now ;;
But I realized that I don't actually need to save expired time of token in database since JWT token is already generated with expired time.

