I have the following query
let mercadoLivreCredencialDB = await mercadoLivreCredencial.findOne({
where: { id : 1 }
});
if(mercadoLivreCredencialDB.data < someJavascriptWay){// I need to calculate if the data column has a datetime that is less than six hours based on the current time
}
I am using node with Javascript. Any help would be welcome. My data column is time stamp without time zone ex: "2023-04-29 23:45:17.833445"
2
Answers
Let’s assume the returned type can be one of the following:
Date
object,string
(ISO compatible) ornumber
(UNIX timestamp), we can then convert all of them to UNIX timestamp in milliseconds for comparison:You can then use the following:
Saw the other answer, but it seems unneccesarily complicated – Dates are automatically converted to ms when doing calculations and comparisons in JavaScript, so there should not be any need for valueOf, getTime() or any similar attempt to manually convert them…
Assuming the timestamp is UTC/GMT for your date, and your date (in the format you specified) is x, this is all you need:
If the timestamp is in local time zone, rather than UTC, then omit + ‘Z’: