I use Node.js, Postgres and node-postgres . When I try to insert a new record with the current date with code like this:
client.query('INSERT INTO ideas(date) VALUES($1)', [new Date()], ...);
And it works fine without errors. However, when I run the select statement on the database and log the results, the date I give looks like:
Wed Nov 20 2013 19:00:00 GMT-0500 (EST)
This is good, except that when I inserted the record, it was Thursday, November 21st. And the time was 5:47, not 7:00, as the conclusion suggests.
I ran the code a few more times and it kept the same inaccurate date regardless of the time, even after the next hour. This makes me believe that for some reason it only stores the date, not the hour or minute. In addition, the fact that the date is only disabled for one day indicates that the problem may have something to do with the way node-postgres handles the dates.
I know that this is not a problem with Javascript calculating the current date when passing it to the request, because I registered new Date()and was accurate on the date, minute, hour and second.
Any help on this would be greatly appreciated. Thanks!
source
share