Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate date and time fields and turn into datetime postgresql

I have a table with the date and time fields separated

Table1

data           hora            id
2015-01-01    11:40:06          1 
2015-01-01    15:40:06          2
2015-01-02    15:40:06          3 
2015-01-05    10:40:06          4 
2015-01-05    15:40:06          5
2015-01-06    08:23:00          6

Now I need to consult the id between 2015-01-01 12:00:00 12:00:00 and 2015-01-05 12:00:00, , should return the ids 2,3,4. I'm trying to convert and concatenate the date and time fields that are separated in a single datetime field in order to use the 'between' but I can not hit the syntax can someone give an example?

like image 218
csf Avatar asked Jan 08 '15 13:01

csf


1 Answers

It works!

SELECT
    *
FROM
    tableA
WHERE
    (dataemissao + hora) BETWEEN (date '2015-01-21' + time '14:00') 
     AND  (date '2015-01-21' + time '18:00')
like image 127
csf Avatar answered Oct 07 '22 01:10

csf