1

I have a table with two columns of "text" type where in one is a date in format 10.03.2013. and in second is time in format 15:45:32. Since both are text I would like to know if is possible with PostgreSQL those strings compare with windows DateTime value.

I was try to get records with BETWEEN() but didn't get nothing.

"(mydate BETWEEN " & fromdate.Date.ToString & _
       " AND " & todate.Date.ToString & ") AND _
 (mytime BETWEEN " & fromdate.TimeOfDay.ToString & _
       " AND " & todate.TimeOfDay.ToString & ")"

mydate and mytime are columns while fromdate and to date are windows datetime types.

Any advice?

6
  • What language is this supposed to be? Why not first construct a timestamp type of value from the separate date+time fields? Commented Jan 1, 2013 at 22:09
  • This is visual basic where i make commands like strings. Second, because data already exists. Commented Jan 1, 2013 at 22:12
  • Or maybe I understand wrong? Can I construct timmestamp from showed data and mented datatype (text)? And how? Commented Jan 1, 2013 at 22:15
  • Do not store dates or timestamp as text (or varchar). That will give you a lot of trouble in the long run. Always use the proper datatype. Commented Jan 1, 2013 at 23:09
  • 1
    What is visual basic? A basic for visual people :) Commented Jan 1, 2013 at 23:40

1 Answer 1

4

Turn those columns into a timestamp type:

select ...
from ...
where
    to_timestamp(mydate || mytime, 'DD.MM.YYYYHH24:MI:SS') between
        '2012-01-20 10:23:12'
        and
        '2012-01-20 11:47:03'
Sign up to request clarification or add additional context in comments.

5 Comments

Can't get that working. I wrongly represent date in question. Those date is in format 10.03.2013 without last point. May this be a problem?
@user973238 Yes that can be a problem. I edited the answer to accommodate the date format.
@user973238 I mean not the point absence but the dd.mm.yyyy format. I first guessed it was mm.dd.yyyy as in the USA. But after you comment I saw you are from Croatia so it probably is dd.mm.yyyy like here in Brazil.
Of course Colorado, thank you, I will fight forward to get results in this situation.
I finally GET IT :) PostgreSQL is amazing!

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.