Sequelize: How to add 12 hours from now

1.1k Views Asked by At

I want to set my date end default value to the currentDate + 12 hours

i try some stuff but that's not work, if someone could help me

 dateEnd: {
            type: Sequelize.DataTypes.DATE,
            defaultValue: sequelize.fn('NOW') + 'INTERVAL 12 HOUR',

            allowNull: false
        }

thanks

1

There are 1 best solutions below

2
On

You can use sequelize.literal to define a default value that uses DB functions:

dateEnd: {
            type: Sequelize.DataTypes.DATE,
            defaultValue: sequelize.literal('NOW() + INTERVAL 12 hour'),
            allowNull: false
        }