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?
You can use a text compare with the pseudodate field. You can even check minutes, since they’re still in lexicographic order.
or maybe
You can also check with regexp, just in case you get “17:00 to 23:00” or something:
This last check should automatically ignore badly formatted dates.