06/06/2019
A little late, but provided an update.
Sequelize is a powerful ORM (I'm not saying this is the best solution), but it has very poor documentation.
In any case, if you want this to be configured in your models, besides the need to repeat it according to your requests, as other answers indicate what you could do:
const Test = sequelize.define('test', { // attributes name: { type: DataType.STRING, allowNull: false }, createdAt: { type: DataType.DATE, //note here this is the guy that you are looking for get() { return moment(this.getDataValue('createdAt')).format('DD/MM/YYYY h:mm:ss'); } }, updatedAt: { type: DataType.DATE, get() { return moment(this.getDataValue('updatedAt')).format('DD/MM/YYYY h:mm:ss'); } }
If you use dates to provide information in the form: last update, first login, last login. This is the way.
The get function returns a new formatted element, so it cannot be limited by dates! Just remember that this will slow down your request, so use it carefully. ;)
more information (I know that I know, but docs is the name of the game): http://docs.sequelizejs.com/manual/models-definition.html#getters--amp--setters
source share