How to save JS Date.now() in PostgreSQL?

前端 未结 3 2055
野的像风
野的像风 2021-02-04 01:17

I tried to use PostgreSQL timestamp datatype, but it throws an error

ERROR:  date/time field value out of range: \"1489849402536\"

相关标签:
3条回答
  • 2021-02-04 02:09

    Or you can do something similar to this:

    const time = new Date().toISOString();
    

    In your query builder:

    ...
    .update()
    .set({column_name: time})
    
    0 讨论(0)
  • 2021-02-04 02:22

    Use the to_timestamp() postgres function:

    `insert into times (time) values (to_timestamp(${Date.now()} / 1000.0))`
    
    0 讨论(0)
  • 2021-02-04 02:22

    Just in case you are using Sequelize, you can use: sequelize.literal('CURRENT_TIMESTAMP'). Example:

    await PurchaseModel.update( {purchase_date : sequelize.literal('CURRENT_TIMESTAMP') }, { where: {id: purchaseId} } );
    
    0 讨论(0)
提交回复
热议问题