# QuestDB Timestamp in Node.js

**URL:** <https://community.questdb.com/t/questdb-timestamp-in-node-js/747>\
**Category:** Community\
**Tags:** sql, question\
**Created:** [February 12, 2025, 1:44pm UTC](https://community.questdb.com/t/questdb-timestamp-in-node-js/747 "2025-02-12T13:44:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsmart](https://avatars.discourse-cdn.com/v4/letter/j/7cd45c/32.png) [@jsmart](https://community.questdb.com/u/jsmart)\
**Post date:** [February 12, 2025, 1:44pm UTC](https://community.questdb.com/t/questdb-timestamp-in-node-js/747/1 "2025-02-12T13:44:40Z")

</div>

When I execute the following query in the QuestDB panel (localhost:9000), it returns the correct timestamp: `2024-01-01T00:00:00.000000Z` (UTC, as recorded).

```sql
SELECT
    timestamp,
    first(open) AS open,
    max(high) AS high,
    min(low) AS low,
    last(close) AS close,
    sum(volume) AS volume,
    sum(quote_volume) AS quote_volume,
    sum(taker_buy_volume) AS taker_buy_volume,
    sum(taker_buy_quote_volume) AS taker_buy_quote_volume
FROM klines
WHERE symbol = 'BTCUSDT'
SAMPLE BY 1m
ORDER BY timestamp LIMIT 1;

```

However, when running the same query in Node.js using `pg.query`, the timestamp returned is `2023-12-31T19:00:00.000Z`, meaning it incorrectly applies another UTC conversion.

How can I fix this?

as an option you can use:  
`cast(timestamp AS LONG) AS timestamp`

---

<div class="post-metadata">

**Author:** ![nwoolmer](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/nwoolmer/32/24_2.png) [@nwoolmer](https://community.questdb.com/u/nwoolmer)\
**Post date:** [February 12, 2025, 2:18pm UTC](https://community.questdb.com/t/questdb-timestamp-in-node-js/747/2 "2025-02-12T14:18:03Z")

</div>

Unfortunately, some PG Wire clients will convert the timestamp to local time. You can cast the timestamp to long, giving you epoch micros, and then convert them back client-side.

There is a related issue I can dig up in a little while.

---

<div class="post-metadata">

**Author:** ![javier](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/javier/32/29_2.png) [@javier](https://community.questdb.com/u/javier)\
**Post date:** [February 12, 2025, 3:09pm UTC](https://community.questdb.com/t/questdb-timestamp-in-node-js/747/3 "2025-02-12T15:09:55Z")

</div>

It seems in nodejs you can setup the TZ and the pg driver should honour it [Data Types – node-postgres](https://node-postgres.com/features/types#date--timestamp--timestamptz)
