sequelize date code example
Example 1: sequelize date format
model.findAll({
attributes: [
'id',
[sequelize.fn('date_format', sequelize.col('date_col'), '%Y-%m-%d'), 'date_col_formed']
]})
.then(function(result) {
console.log(result);
});
Example 2: sequelize date format
function getDateWithoutTime(date) {
return require('moment')(date).format('YYYY-MM-DD');
}
Example 3: Sequelize date format
var Sequelize;
var DataTypes = Sequelize = require('./index');
var sequelize = require('./test/support').createSequelizeInstance({
logging: console.log
});
var Topic = sequelize.define('topic', {
last_date_time: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.NOW
}
});
return sequelize.sync({
force: true
}).then(() => {
return Topic.update(
{
last_date_time: '2016-08-09 04:05:02',
},
{
where: {id: 42}
}
);
})