0

In our Postgres database, we have the following range for a field:

The value looks like this: (some kind of a slot)

["2015-02-06 18:30:00","2015-02-06 19:00:00")

We would like out of it to select only the first component: 2015-02-06

We tried several functions: LEFT, SUBSTRING, TO Char but they are all giving errors.

Any idea how we could solve this?

0

2 Answers 2

3

You haven't shown the table definition but it seems that your column is a tsrange.

You need to extract the lower element of the range which gives you a timestamp and then cast that to a date:

select lower(the_column)::date
from the_table;

See the manual for more details:

Sign up to request clarification or add additional context in comments.

1 Comment

I will ask you an additional question because I really want to understand! We have to different field: on is like this 2015-01-27 13:35:51.905 and to separate we used the formula to_char("domain".bookings.created_at,'FMDD.MM.YYYY') What is the difference with lower ? I check your documentation but I couldn't find the answer... Thank you!
-1

If you want to get the date from timestamp you should cast timestamp to date using ::date

SELECT your_timestamp_column::date FROM table_name  
where your_timestamp_column::date='date' 

2 Comments

Thank you! It works, I am gonna use it for several other fields!
you are welcome, would you please recomonde this answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.