I have a postgres table with a column "date" which is a string with the basic javascript date format:
"Tue Dec 29 2020 23:16:54 GMT-0800 (Pacific Standard Time)"
I am wondering if there is a way to query by date even though it's in a string format like that. In my node backend, I am currently doing this:
pool.query("SELECT * FROM table WHERE field1 = $1 ORDER BY date DESC LIMIT 10", [val1], (err, table) => {
if(err) {
return res.status(400)
done()
} else {
res.json(table.rows)
}
})
This appeared to be working at first but since adding more records it is not really working correctly. If there is a fix for this that doesn't involve redoing the date column, I would be infinitely grateful as I've already built out a lot of code around that date string format. Thank you in advance.
Date, but in the long run changing thedatecolumn toDATETIMEorTIMESTAMPis the correct solution.