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 6110497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:31:21+00:00 2026-05-23T14:31:21+00:00

Running PostgreSQL 7.4(Yep we’re upgrading) Field is data type: timestamp with time zone Format

  • 0

Running PostgreSQL 7.4(Yep we’re upgrading)

Field is data type: timestamp with time zone

Format is like this: 2011-06-30 19:18:07-04

Converting to this format:

to_char(datetime_field, 'MM-DD-YYYY HH12:MI:SS') AS "New Date"

Output is this:

06-30-2011 07:18:07

But I also need to add the meridian indicator.

Desired results:

// if AM
06-30-2011 07:18:07 AM

// if PM
06-30-2011 07:18:07 PM

Is there a option I can pass to get this?

So the example datetime I give

2011-06-30 19:18:07-04

should be this:

06-30-2011 07:18:07 PM

UPDATE:

Well I’m still looking for an option to pass but this is a workaround I did:

CASE WHEN date_part('HOUR', datetime_field) > 12
     THEN to_char(datetime_field, 'MM-DD-YYYY HH12:MI:SS PM')
     ELSE to_char(datetime_field, 'MM-DD-YYYY HH12:MI:SS AM')
END AS "New Date"
  • 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-23T14:31:22+00:00Added an answer on May 23, 2026 at 2:31 pm

    According to the documentation page (for v8.2), you can use any pattern from this list: AM, am, PM, pm, A.M., a.m., P.M., p.m.. The pattern chosen will define the style of the indicator in the output, but whether it will be ante meridiem or post meridiem, will entirely depend on the timestamp value.

    So you don’t need to employ CASE at all. Use whatever of the two:

    • to_char(datetime_field, 'MM-DD-YYYY HH12:MI:SS AM') AS "New Date"

    • to_char(datetime_field, 'MM-DD-YYYY HH12:MI:SS PM') AS "New Date"

    Was that what you were asking about?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running PostgreSQL (7.4 and 8.x) and I thought this was working but now I'm
I'm running PostgreSQL on mt Windows 7 machine. To run a database I type:
I'm running: PostgreSQL 9.0.3 (Last Debian stable) This query: SELECT * FROM sis.thread_categories stc,
I have postgresql running (/opt/local/lib/postgresql90/bin). The data base is set up @ /Users/demet8/postgres/data. I
I'm running this under windows vista cmd prompt: java -classpath C:\postgresql-8.4-701.jdbc4.jar -jar myJar.jar I
I am running rails 3.1.3 with postgresql 9.1 and testing with Rspec. This is
I am getting this error when running heroku rake db:migrate: Please install the postgresql
I have a really big database (running on PostgreSQL) containing a lot of tables
I have a Rails 2.0.2 application running with a postgresql db. The machine will
I'm running a query against a table in a postgresql database. The database 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.