Reputation: 3382
I am having a table oauth_refresh_token like you can see below:
var OAuthRefreshToken = myDb.define("oauth_refresh_token", {
refresh_token: {type: sequelize.STRING, primaryKey: true}
client_id: {type: sequelize.STRING}
});
Sequelize automatically creates the columns "created_at" and "updated_at" for me with the datatype: "timestamp with time zone".
Now when I want to ask how to compare 2 dates with each other. I want to get an Object of this type if it was created in the last 24h. I have something like this so far:
var currentTimeMinus24Hours = new Date()-24*60*60*1000;
return OAuthRefreshToken.find(
where: {
refresh_token: token
updated_at: { gt: currentTimeMinus24Hours }
}
)
If I do this code I get an exception that operator does not exists: timestamp with time zone > bigint. Makes sense, but any Idea how I can make it work. If it helps you. I am using a postgres database.
Upvotes: 1
Views: 10967
Reputation: 8798
I use the momentjs library
calling moment().format()
will give you the date time in timestamptz format.
There are also many reasons why you should use moment because it is a solid library that deals away with many problems associated with manipulating time.
However I am interested to see if there are other vanilla solutions.
Upvotes: 5