백엔드/DB
[mysql] cannot check if timestamp is between varchar(23) and varchar(23) - 날짜 조회 쿼리
작은소행성
2021. 9. 28. 13:34
sql에서 timestamp 형식의 날짜에서 날짜와 날짜 사이의 데이터를 조회하고자 한다.
date 컬럼의 날짜의 형식은 timestamp 이며, 조회하고자 하는 날짜는 문자열로 조회하려고 했다.
기존쿼리문
select *
from table1
where date between '2021-09-28 12:00:00.000' and '2021-09-28 18:00:00.000'
문자열로 표시한 날짜 앞에 timestamp 를 붙여서 사용하면 조회가 가능하다.
select *
from table1
where date between timestamp '2021-09-28 12:00:00.000' and timestamp '2021-09-28 18:00:00.000'
반응형