How to search up data "from - to" a time date

SirTennant's profile image SirTennant posted 4 years ago in General Permalink

Hello, basically my question is... how do I select data from my database basically from date like 7th of august up to 9th of august?

This is what I'm trying to use right now

select * FROM chat WHERE TIME FROM 2020-09-20 TO 2021-09-21;

I also tried:

select * FROM chat WHERE TIME LIKE FROM 2020-09-20 TO 2021-09-21;

And:

select * FROM chat WHERE TIME FROM 2020-09-20 15:20:39 TO 2021-09-21 15:20:39;

None of it works. Sorry if this is really trivial, but I'm not really experienced with this.

Thanks for your help in advance!

3 attachment(s):
  • Screenshot_1
  • Screenshot_2
  • Screenshot_3
ansgar's profile image ansgar posted 4 years ago Permalink

You're almost there:

SELECT ... WHERE `time` BETWEEN '2020-09-20 15:20:39' AND '2021-09-21 15:20:39'
SirTennant's profile image SirTennant posted 4 years ago Permalink

You're almost there:

SELECT ... WHERE `time` BETWEEN '2020-09-20 15:20:39' AND '2021-09-21 15:20:39'

Thanks a lot, that works!

ansgar's profile image ansgar posted 4 years ago Permalink

Note that you can even leave some parts away from the right side:

SELECT ... WHERE `time` BETWEEN '2020-09-20 15' AND '2021-09-21'

Another way is to use the LIKE operator, useful in situations where you want to leave away the date:

SELECT ... WHERE `time` LIKE '% 15:__:__'

Please login to leave a reply, or register at first.