SQL searching records from a Date and Time

Asked

Viewed 1,806 times

2

I have the following SQL:

select * from tb_valores
where
DATA >= '14/12/17' and
HORA >= '16:34:00')

I would like to bring all records from that date and time.

The problem is that if I have records like:

'14/12/17' '10:20:00'
'14/12/17' '13:20:00'
'14/12/17' '16:32:00'
'18/12/17' '08:00:00'

he doesn’t bring these records.

  • So it doesn’t work? select * from tb_values Where (DATA >= '14/12/17') and ( TIME >= '16:34:00')

  • 1

    All listed records are less than "16:34:00", so it’s not bringing results. The other error is with SQL syntax.

  • In your table this field DATA is a Date? and that field Hour and a Time?

  • If possible add the structure of your table and the type of data that are these fields, if you want to catch the time is simple, just take the date, it was not very clear to me

3 answers

0

James, Jovani’s code runs, I’ve seen it now.

just take a quote right after the 17, which works.

Leave it at that:

    select * from tb_valores where (DATA >= '14/12/17') and ( HORA >= '16:34:00') 

Instead of like this:

    select * from tb_valores where (DATA >= '14/12/17 '') and ( HORA >= '16:34:00')

If it still doesn’t work, send Create Statment from your table.

0


James, you can do something like this:

SELECT * FROM tb_valores WHERE (DATA > '14/12/17' OR (DATA = '14/12/17' AND HORA >= '16:34:00'))

This way the query will search all data with date is greater than "12/14/17", which consequently will be greater than "12/14/17 16:34:00", or data with date equal to "12/14/17" but time greater or equal to "16:34:00".

0

So it doesn’t work?

select * from tb_valores where (DATA >= '14/12/17 '') and ( HORA >= '16:34:00') 
  • Jovani, it doesn’t work, because if I have values below the time '16:34:00' it doesn’t search.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.