ID photo of Ciro Santilli taken in 2013 right eyeCiro Santilli OurBigBook logoOurBigBook.com  Sponsor 中国独裁统治 China Dictatorship 新疆改造中心、六四事件、法轮功、郝海东、709大抓捕、2015巴拿马文件 邓家贵、低端人口、西藏骚乱
nodejs/sequelize/date.js
#!/usr/bin/env node
// https://cirosantilli.com/sequelize-example
const assert = require('assert')
const { DataTypes, Op } = require('sequelize')
const common = require('./common')
const sequelize = common.sequelize(__filename, process.argv[2])
;(async () => {
// Datetime. Automatically converts to/from date objects.
const Dates = sequelize.define('Dates', {
  date: {
    type: DataTypes.DATE,
  },
}, {})
await Dates.sync({force: true})
let dateCreate = await Dates.create({date: new Date(2000, 0, 1, 2, 3, 4, 5)})
await Dates.create({date: new Date(2000, 0, 1, 2, 3, 4, 6)})
await Dates.create({date: new Date(2000, 0, 1, 2, 3, 4, 7)})
let date = await Dates.findOne({
  order: [
    ['date', 'ASC'],
  ],
})
assert.strictEqual(date.date.getTime(), new Date(2000, 0, 1, 2, 3, 4, 5).getTime())
assert.strictEqual(date.date.getTime(), dateCreate.date.getTime())
})().finally(() => { return sequelize.close() })