I'm using Vercel Postgres (Neon), and my table has a column start_date stored as a DATE type. However, when I query it, PostgreSQL always returns a full timestamp (YYYY-MM-DDTHH:MM:SSZ) instead of just the YYYY-MM-DD date.
Table Schema:
CREATE TABLE share_buyback_programs (
id SERIAL PRIMARY KEY,
equity_isin TEXT,
start_date DATE, -- Stored as DATE, but returns TIMESTAMP
end_date DATE,
size NUMERIC
);
SQL Query:
SELECT start_date FROM share_buyback_programs;
Expected Output:
2025-02-07
Actual Output:
2025-02-06T16:00:00.000Z
This happens even though the column is of type DATE, not TIMESTAMP.
What I've Tried: Casting as TEXT → Still returns a timestamp in some cases:
SELECT start_date::TEXT FROM share_buyback_programs;
Adjusting time zones (AT TIME ZONE):
SELECT start_date AT TIME ZONE 'UTC' AT TIME ZONE 'Asia/Manila' FROM share_buyback_programs;
Checking the actual stored values:
SELECT column_name, data_type FROM information_schema.columns
WHERE table_name = 'share_buyback_programs' AND column_name = 'start_date';
Confirms it's stored as DATE, not TIMESTAMP.
Trying to fix it in JavaScript using moment.js:
import moment from "moment";
const result = await sql`SELECT start_date FROM share_buyback_programs`;
const formattedDate = moment(result.rows[0].start_date).format("YYYY-MM-DD");
console.log(formattedDate); // Still logs 2025-02-06, not 2025-02-07
My Environment:
Database: PostgreSQL (Neon via Vercel)
Driver: @vercel/postgres
Timezone Settings: Vercel/Neon defaults to UTC
Query Language: Node.js / Next.js API Route
Question: Why does Neon/Vercel Postgres return a TIMESTAMP instead of a DATE for start_date? How can I ensure it only returns YYYY-MM-DD without manually formatting the output every time?
Any help is appreciated!
result.rows[0].start_date? I'm guessing it'sDate. What Javascript callsDateis really a timestamp. So your PostgreSQL Date is being turned into a Javascript Date (timestamp). Also, use of moment is being discouraged.