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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:08:15+00:00 2026-05-25T16:08:15+00:00

Currently my table has a column to store date and time. The data type

  • 0

Currently my table has a column to store date and time. The data type of that column is timestamp without time zone. So it has values in the format '2011-09-13 11:03:44.537'.

I need to retrieve rows with respect to the date. If I use:

select * from table where mdate >= '2011-09-13 11:03:44.537'
                      and mdate <= '2011-09-12 11:03:44.537'

it will provide the values which are in between ‘2011-09-13 11:03:44.537’ and ‘2011-09-12 11:03:44.537’.

But if I am going with:

select * from table where mdate >= '2011-09-13 00:00:00.0'
                      and mdate <= '2011-09-12 00:00:00.0'

without date, month and seconds, It is not displaying any rows.

How to fetch values from this table with respect to the date (only with date, ignoring hour, minutes and seconds)?

Even, the column has date with timestamp, I need to search them only with date (ignoring timestamp or making the hour, minutes and seconds to 0 such as '2011-09-13 00:00:00.0').

  • 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-25T16:08:16+00:00Added an answer on May 25, 2026 at 4:08 pm

    If you are going to cast the timestamp values of the field to date, as suggested in another answer, performance will degrade because every single value in the column needs to be cast for comparison and simple indexes cannot be used. You would have to create a special index on the expression, like so:

    CREATE INDEX some_idx ON tbl (cast(mdate AS date));
    

    In this case the query should also be simplified to:

    SELECT * FROM tbl
    WHERE  mdate::date = '2011-09-12'::date; -- 2nd cast optional
    

    However, as far as I can see, your problem is a simple typo / thinko in your query:
    You switched upper & lower boundaries. Try:

    SELECT * FROM tbl
    WHERE  mdate >= '2011-09-12 00:00:00.0'
    AND    mdate <= '2011-09-13 00:00:00.0';

    Or, to simplify your syntax and be more precise:

    SELECT * FROM tbl
    WHERE  mdate >= '2011-09-12 00:00'
    AND    mdate <  '2011-09-13 00:00';
    
    • There is no need to spell out seconds and fractions that are 0.
    • You don’t want to include 2011-09-13 00:00, so use < instead of <=.
      Don’t use BETWEEN here, for the same reason:
    WHERE mdate BETWEEN '2011-09-12 00:00' AND '2011-09-13 00:00'

    This would include 00:00 of the next day.

    Also be aware that a column of type timestamp [without time zone] is interpreted according to your current time zone setting. The date part depends on that setting, which should generally work as expected. More details:

    • Ignoring time zones 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 currently have a table which only has a single editable column. I have
I have a table that has an AUTO_INCREMENT field. Currently, it is also a
I currently have a table that is 17 columns wide and has 30 records.
I'm currently working with MS SQL 2005, and have a table that has 17
I currently am using existing code that has Sql.Append(UPDATE Store SET + LogoAlign=' +
Here is the scenario: SQL Server 2000 (8.0.2055) Table currently has 478 million rows
I have a table in MySQL 4.0 which currently has a year field as
I currently have a table structure that looks something like this(some details omitted): ColumnName
I'm trying to normalize a mysql database.... I currently have a table that contains
Currently we have a table that we use to track inivitations. We have an

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.