question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to update Sequelize.DATE TYPE?

See original GitHub issue
  last_date_time: {
    type: Sequelize.DATE,
    allowNull: false,
    defaultValue: Sequelize.NOW
  }

I use momentjs to get the time But when I update the last_date_time, sequelize just Executing (default): UPDATEtopicsSETupdatedAt='2016-08-09 07:42:28' WHEREid= '53' I tried some format,all the same

(new Date()).format('yyyy-MM-dd hh:mm:ss')
moment().format('yyyy-MM-dd hh:mm:ss')
moment.utc().format()
Sequelize.NOW

Topic.update(
    {
      last_data_time: Sequelize.NOW,
    },
    {
      where: {id: id}
    }
  );

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

18reactions
hezhongfengcommented, Aug 9, 2016

@janmeier It worked. I changed nothing. I’m happy. Thank you for your answer. I will close this issue.

0reactions
janmeiercommented, Aug 9, 2016
/*
 * Copy this file to ./sscce.js
 * Add code from issue
 * npm run sscce-{dialect}
 */

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}
    }
  );
})
UPDATE `topics` SET `last_date_time`='2016-08-09 04:05:02',`updatedAt`='2016-08-09 08:19:37' WHERE `id` = 42
Read more comments on GitHub >

github_iconTop Results From Across the Web

Data Types
To access a built-in data type, you must import DataTypes : ... DATE(6), TIMESTAMP(6) WITH TIME ZONE, DATETIME(6), DATETIME(6), DATETIMEOFFSET(6), TEXT ...
Read more >
Sequelize - how to format the date for date types values
First, create a Sequelize model of the above table. The invoiceDate column uses the DATEONLY type while paymentDate column uses DATE type as ......
Read more >
How to update with Sequelize with 'NOW()' on a timestamp?
You can use Sequelize.fn to wrap it appropriately: instance.updateAttributes({syncedAt: sequelize.fn('NOW')});.
Read more >
sequelize-typescript
In order to update the types for sequelize please go to the Definitely Typed repo, it would also be a good idea to...
Read more >
sequelize.SequelizeStatic.DATE JavaScript and Node.js ...
value: DataTypes.INTEGER, updated_at: DataTypes.DATE. ... BOOLEAN, defaultValue: true }, sequence: { type: Sequelize.INTEGER, defaultValue: 0, trim: true } ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found