Home > Enterprise >  Find elements between date and time intervals MySQL
Find elements between date and time intervals MySQL

Time:08-28

How do I query a SQL Database to search trough a date and time interval when I have different columns for date and time ?

SELECT  * FROM prices.prices WHERE data BETWEEN CAST('2020-01-06' AS DATE) AND CAST(Var3 >='12:41' AS TIME) AND CAST('2020-01-10' AS DATE) AND CAST(Var3 <= '14:59' AS TIME);

This above doesnt work...

Where Var3 is the time column and data is the date column

CodePudding user response:

If the datatype of the column 'data' is date, no need to use cast function anymore

SELECT
    * 
FROM
    prices
WHERE
    (data >= '2020-01-06' AND var3 >= (CAST('12:41' as time))) AND
    (data <= '2020-01-10' AND <= (CAST(Var3 '14:59' as time)))

Try this out. Not sure is what you want, cause your question didn't make it clear

  • Related