Skip to content

While retrieving Timestamp values from DB it is adding 4 hours to it. #2525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SagarPattnayak opened this issue Apr 21, 2021 · 7 comments
Closed

Comments

@SagarPattnayak
Copy link

Hi,
I am using "pg" in one of my nodeapp. The timestamp values i insert programmatically is inserting correct time. However while retrieving the same via pool.query, it is adding 4 hours to it. How to address this?

File1 is from DB & File2 id while retrieving.
File1
File2

Appreciate any feedback suggestion.

@charmander
Copy link
Collaborator

See #2390 (comment). If your column represents moments in time, though – it sounds like it does – it should probably be a timestamp with time zone. That data type works intuitively in pg.

@vitaly-t
Copy link
Contributor

timestamp with time zone = timestamptz 😉

@SagarPattnayak
Copy link
Author

I have tried both with timestamp and timestamptz datatype. Same issue. So as a work around I am using varchar as datatype for datetime fields.

@charmander
Copy link
Collaborator

If the same thing is happening with timestamptz, there’s probably something incorrect about one of the queries involved, the way you’re processing the results, or the way you’re passing in the parameter. Without seeing any code it’s hard to say though.

@msantana-dev
Copy link

msantana-dev commented Apr 27, 2021

See my comment here #2530 (comment)

@jpschw
Copy link

jpschw commented Mar 6, 2023

For anyone else having trouble - You're probably testing locally and it's picking up your local timezone from NodeJS.
Put this at the start of your program if you intend to always work in the same timezone across all envs. In this case UTC.
process.env.TZ = "UTC+0";

@charmander charmander closed this as not planned Won't fix, can't repro, duplicate, stale Mar 6, 2023
@mfvas
Copy link

mfvas commented Apr 23, 2025

Another way to "fix" this is to set:

pg.defaults.parseInputDatesAsUTC = true;

which makes it assume that all your DB timestamps are in UTC time, as far as I understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants