Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5938499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:41:41+00:00 2026-05-22T15:41:41+00:00

I want to extract just the date part from a timestamp in PostgreSQL. I

  • 0

I want to extract just the date part from a timestamp in PostgreSQL.

I need it to be a postgresql DATE type so I can insert it into another table that expects a DATE value.

For example, if I have 2011/05/26 09:00:00, I want 2011/05/26

I tried casting, but I only get 2011:

timestamp:date
cast(timestamp as date)

I tried to_char() with to_date():

SELECT to_date(to_char(timestamp, 'YYYY/MM/DD'), 'YYYY/MM/DD') 
FROM val3 WHERE id=1;

I tried to make it a function:

CREATE OR REPLACE FUNCTION testing() RETURNS void AS '
DECLARE i_date DATE;
BEGIN
    SELECT to_date(to_char(val1, "YYYY/MM/DD"),"YYYY/MM/DD") 
      INTO i_date FROM exampTable WHERE id=1;
    INSERT INTO foo(testd) VALUES (i);
END

What is the best way to extract date (yyyy/mm/dd) from a timestamp in PostgreSQL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:41:42+00:00Added an answer on May 22, 2026 at 3:41 pm

    You can cast your timestamp to a date by suffixing it with ::date. Here, in psql, is a timestamp:

    # select '2010-01-01 12:00:00'::timestamp;
          timestamp      
    ---------------------
     2010-01-01 12:00:00
    

    Now we’ll cast it to a date:

    wconrad=# select '2010-01-01 12:00:00'::timestamp::date;
        date    
    ------------
     2010-01-01
    

    On the other hand you can use date_trunc function. The difference between them is that the latter returns the same data type like timestamptz keeping your time zone intact (if you need it).

    => select date_trunc('day', now());
           date_trunc
    ------------------------
     2015-12-15 00:00:00+02
    (1 row)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have people inputting 125px and 125% I want to extract just 125 from
In my bash script I need to extract just the path from the given
I have a DateTime column. I want to extract all records, lets say, from
I have some DateTime s in my model. I only want to extract the
I want to split this string up into parts like Source: Web, Pics: 1
I have a table that has a START_DATE and an END_DATE column. I want
Is there a tool for Windows that can read the Delphi history files. and
So, I've got a little translation system set up for my app, where we
I'm creating a basic system that allows users to reply to a thread on
I am new to perl so please accept my apologies if my question is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.