Reputation: 31
I am using moment as a third part library. Every time a record is created in the model the date is stored with 0:00 time. Such as Thu Dec 03 2015 00:00:00 GMT+0200 (EET) .
var dateToday = moment(moment().format("YYYY-MM-DD HH:mm")).toISOString();
This is the date I am putting in the date field. I've also tried with toDate() and new Date()... the same. When I try to print it, the time is OK, but when I put it in a record it is always stored as 0:00.
Upvotes: 1
Views: 3197
Reputation: 665
const moment = require('moment');
Here is a working example on how to save date (now) into MYSQL DB through ORM of Sails.js
:
moment().format('YYYY-MM-DD HH:mm:ss')}
With the ORM class:
await TagsToScrape.update({
id: hashTag.id
}).set({lastProcessStarted: moment().format('YYYY-MM-DD HH:mm:ss')});
P.S. You can always check whether time is valid like this:
moment().format('YYYY-MM-DD HH:mm:ss')}.isValid() // true
Upvotes: 1
Reputation: 5979
What is your Database adapter? You DB field could be set to a simple date format?
Otherwise you should update your question with you DB Adapter and your Model definition (and if using SQL database, your scheme for that field)
You should be using datetime
as your attribute values.
Upvotes: 1