Select between date range and specific time range

Viewed 17576

Is there a way to Select records between dates and specific time range. For example all the records from 2013-11-01 to 2013-11-30 between hours 05:00 to 15:00. Here what i made until now.

    select count(*) as total from tradingaccounts accounts
inner join tradingaccounts_audit audit on audit.parent_id = accounts.id
where date(audit.date_created) between date('2013-11-01 00:00:00') AND date('2013-11-01 23:59:59') 

But how am I going to set the specific time range?

5 Answers

If you use date(audit.date_created), the index on date_created field could not take effect.

Just simply use where audit.date_created >= 'xx-xx-xx' and audit.date_created < 'xx-xx-xx'

Related