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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:56:45+00:00 2026-06-13T07:56:45+00:00

In PostgreSQL I have a text column that contains values representing start and stop

  • 0

In PostgreSQL I have a text column that contains values representing start and stop times of events in this format: “15:00-17:00” (e.g. that’s an event that starts at 3pm and ends at 5pm). I need to write an SQL query that returns rows where the event has not yet ended. For example, if I query at 16:48, the event above would be returned because it is not yet 17:00. If it helps, I’m only concerned with the hour value, minutes can be ignored.

If the data were in proper time fields, this would be trivial but I’m little baffled as to how to do it when the data is text. I assume I can use some kind of regex to parse out just the 2nd hour value and maybe combine that with CURRENT_TIME for some kind of comparison but I’m not really sure how to put it all together.

Can anyone help me out?

  • 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-13T07:56:46+00:00Added an answer on June 13, 2026 at 7:56 am

    You can use a text compare with the pseudodate field. You can even check minutes, since they’re still in lexicographic order.

    ... WHERE SUBSTR(datefield, 7, 5) >= to_char(NOW(), 'HH24:MI');
    

    or maybe

    ... WHERE split_part(datefield, '-', 2) >= to_char(NOW(), 'HH24:MI');
    

    You can also check with regexp, just in case you get “17:00 to 23:00” or something:

    ... WHERE substring(datefield from '\d\d:\d\d$') >= to_char(NOW(), 'HH24:MI')
        AND   substring(datefield from '^\d\d:\d\d') <= to_char(NOW(), 'HH24:MI');
    

    This last check should automatically ignore badly formatted dates.

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

Sidebar

Related Questions

I have a text[] ARRAY column within a PostgreSQL table and I need to
I have a table in PostgreSQL where a column is a text. I need
As in title. I have one column which has some text values. For example
I have a table that has 20 integer columns and 1 text column named
Background: I have a PostgreSQL (v8.3) database that is heavily optimized for OLTP. I
That title is presumably awfully worded. I have some PostgreSQL tables. There is a
I have a postgres function that returns two columns result, data (int), (text) If
I have a column that is bytea in postgres, and I can use a
I want rename all column names to lower case in PostgreSQL database I have
I have a PostgreSQL (9.0) database with a column card_id which is currently of

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.