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

  • SEARCH
  • Home
  • 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 7837047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:26:37+00:00 2026-06-02T14:26:37+00:00

I have a table with a date and time field. I’m having difficulty understanding

  • 0

I have a table with a date and time field. I’m having difficulty understanding how I deal with this, partially as I don’t understand how time can be converted to a number. I made a table using the following command:

CREATE TABLE tracking.time_record
(
  date date, 
  "time" time without time zone,
  id character(100)
)

An example of my data is as follows:

"2012-04-18" | "18:33:19.612" | "2342342384" 

How can I run a query such that I can examine all of the id values that have a time value > 10 pm on a certain day, for example?

I realize that as my time is stored in a character type variable so something like this does not work:

SELECT * FROM tracking.time_record 
WHERE "time" > "04:33:38.884" AND date > "2012-04-18"

(This is my first exploration of time/date tracking – I should probably have chosen different column names)

  • 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-06-02T14:26:40+00:00Added an answer on June 2, 2026 at 2:26 pm

    Neither of the answers so far captures your actual problem(s).

    While an explicit cast to the appropriate type certainly doesn’t hurt, it is not necessary. PostgreSQL coerces a string literal to the appropriate type automatically.

    Your problems stem from basic syntax errors:
    Double quotes are for identifiers: "MyColumn" – and only necessary for otherwise illegal identifiers (mixed case, reserved word, ..) which should be avoided to begin with.
    Single quotes are for values: 'string literal'.

    You might be interested in the well written chapters on identifiers and constants of the PostgreSQL manual.

    While we are at it, never use date or time as column names. Both are reserved words in every SQL standard and type names in PostgreSQL. This will lead to confusing code and error messages.

    I would recommend to just use a single timestamp column instead of separate date and time:
    And you almost certainly don’t want character(100) as data type, ever – especially not for an id column. This blank-padded type is basically only there for historic reasons. Consider text or varchar instead:

    • Any downsides of using data type "text" for storing strings?

    Could look like this:

    CREATE TABLE tbl (
       tbl_id text CHECK(length(id) <= 100)
     , ts timestamp
    );
    

    Cast to time or date where you only need these components, it’s short and cheap:

    SELECT ts::time AS the_time, ts::date AS the_date FROM tbl;
    

    Use date_trunc() or extract() for more specific needs.
    To query for … id values that have a time value > 10 pm on a certain day:

    SELECT *
    FROM   tbl
    WHERE  ts::time > '22:00'
    AND    ts::date = '2012-04-18';
    

    Or, for any continuous time period:

    ...
    WHERE  ts > '2012-04-18 22:00'::timestamp
    AND    ts < '2012-04-19 00:00'::timestamp;
    

    The second form can use a plain index on ts better and will be faster in such cases for big tables.

    More about timestamp handling in PostgreSQL:

    • Ignoring timezones altogether in Rails and PostgreSQL
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table that contain date and time field. id|date|time ========= 1|01/01/2001|10:45 2|01/02/2002|11:45 3|01/03/2003|12:45
I have a table in SQL Server 2005 which has a date time field.
I have a MySQL table where there is a 'date_added' (date) field, 'time_added' (time)
i have a table that has a date/time field when i display the report,
I have a datetime field in my MySql table where the date and time
I have table Proccesses that consist of Date Time Field. Proccesses ( Id as
I have table Proccesses that consist of Date Time Field. Proccesses ( Id as
I have table with date/time column and person column. Each person has multiple records
I have a table containing reports and the date/time they were created. I'd like
I have a table with a date field type date . What I am

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.