Just trying to do some simple messaging here:
var post = {
sender_username : sender_username,
recipient_username : recipient_username,
message_no : 1,
content : content,
time : ***CURRENT TIMESTAMP***,
read : 0
};
connection.query('INSERT INTO message SET ?', post, function(err, result) {
if (err) {
res.send(err);
}
else {
res.send(post);
}
});
What's the simplest way to stick the date and time in there that is valid for the TIMESTAMP type?
You can use Moment.js for this purpose:
Date.now returns current timestamp in millisecond and moment also works with milliseconds.
var mysqlTimestamp = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With