I've tried to select all records in a table with the timestamp in the dateformat 2011-08-01-
12:00:00
Using the following code:
SELECT f.`fly_reg`, RIGHT(f.`start_tid`,8) AS st, f.`start_hight`
FROM vbsk_dk_02.fab_master_flyvedata f
Where st between 12:00:00 AND 18:00:00
But can't get it to work
SELECT col1, col2, col3 FROM table WHERE DATE_ADD(last_seen, INTERVAL 10 MINUTE) >= NOW(); This adds 10 minutes to last_seen and compares that against the current time. If the value is greater, last_seen is less than ten minutes ago. See the documentation on DATE_ADD() for an explanation of how it is used.
How do I find last 30 days in SQL? SELECT * FROM product WHERE pdate >= DATEADD(day, -30, getdate()).
How to Select rows from a range of dates with MySQL query command. If you need to select rows from a MySQL database' table in a date range, you need to use a command like this: SELECT * FROM table WHERE date_column >= '2014-01-01' AND date_column <= '2015-01-01';
You've got two issues here:
TIME()
function to extract the time part of the datatimeWith those two issues addressed, you get:
select
f.fly_reg,
TIME(f.start_tid) AS st,
f.start_hight
FROM vbsk_dk_02.fab_master_flyvedata f
where TIME(f.start_tid) between '12:00:00' AND '18:00:00'
As an option, if you don't actually need the time value in the select, you can remove it and just have it in the where clause. Also, you can use the HOUR()
function if that suits better. With those two changes in, your query would simplify to:
select *
FROM vbsk_dk_02.fab_master_flyvedata
where HOUR(f.start_tid) between 12 and 18
which is a lot neater :)
If you have stored the time in a column of type "Timestamp" or "Datetime", you can select a range of records between hours like this:
select * from testTable where hour(`timeStampCol`) >= 12 and hour(`timeStampCol`) <= 18
I tested this with this setp up:
CREATE TABLE `cm`.`testTable` (
`timeStampCol` TIMESTAMP NOT NULL,
`dateTimeCol` DATETIME NOT NULL
)
ENGINE = MyISAM
COMMENT = 'Delete this table';
insert into testTable values ('2010-01-01 14:52:00', '2010-01-01 14:52:00')
insert into testTable values ('2010-01-01 19:48:00', '2010-01-01 19:48:00')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With