How to format the datetime in the raw query, my database is mysql. The format i want is YYYY-MM-DD HH:mm:SS
, but now it is YYYY-MM-DDTHH:mm:ss:000Z
.
Asked
Active
Viewed 936 times
1
-
What languages do you use? PHP? – Ryuk Lee May 08 '18 at 02:31
-
No, i use javascript, Node.js – May 08 '18 at 02:33
-
[Try this](https://stackoverflow.com/questions/49893279/convert-facebook-json-created-time-of-string-format-to-other-format/49893562#49893562) – Ryuk Lee May 08 '18 at 02:36
-
Thank you, but this not work – May 08 '18 at 02:41
-
show me your code please – Ryuk Lee May 08 '18 at 02:43
-
data = await sequelize.query(sql, { type: QueryTypes.SELECT }); – May 08 '18 at 02:45
-
It's not clear. You need to parse your date first, then put it in to your query – Ryuk Lee May 08 '18 at 02:50
-
My sql is 'SELECT updateTime from mytable', the 'updateTime' field type is DATETIME, in query result, the format is 'YYYY-MM-DDTHH:mm:ss:000Z', i want fromat is 'YYYY-MM-DD HH:mm:ss' – May 08 '18 at 02:57
-
For example `2018-05-08T10:02:30.000Z` right? – Ryuk Lee May 08 '18 at 03:04
-
Yes, but i need is like '2018-05-08 10:02:30' – May 08 '18 at 03:11
-
Ok I have no idea about Sequelize. Good luck – Ryuk Lee May 08 '18 at 03:30
1 Answers
-1
In defaults option, Sequelize return UTC format.
If you want to change it to YYYY-MM-DD HH:mm:ss
add dateStrings: true
in dialectOptions
example :
const options = {
host: process.env.MYSQL_HOST,
port: process.env.MYSQL_PORT,
dialectOptions: {
dateStrings: true
}
logging: true
};
const sequelize = new Sequelize(process.env.MYSQL_NAME, process.env.MYSQL_USER, process.env.MYSQL_PASS, options);