Reputation: 611
I have such knex
statement:
return knex(table).insert({
id: uuid.v4(),
...data,
created_at: knex.raw('CURRENT_TIMESTAMP'),
updated_at: knex.raw('CURRENT_TIMESTAMP'),
expired_at: ...
})
There are 3 timestamp fields created_at
, updated_at
and expired_at
. There is no problem with 2 first, but I have no idea, how to add expired_at
like +1 minute.
On pseudocode I would look like:
expired_at: knex.raw('CURRENT_TIMESTAMP + 1 minute')
So, how can I add time using CURRENT_TIMESTAMP
?
Upvotes: 2
Views: 2099
Reputation: 2985
you can use knex.fn.now()
to execute CURRENT_TIMESTAMP
function on the database and you will need to use mysql built in methods to calculate your future date
have a look on mysql date functions in the offical doc
for example:
knex.raw('SELECT date_add(?, INTERVAL ? day)', [knex.fn.now(), 1])
Upvotes: 4