develog

[MySql] 날짜 검색 본문

DB/MySQL

[MySql] 날짜 검색

냐옴 2019. 3. 7. 10:38

 

-- 2019-02-22 일자만 검색

AND REG_TS >= STR_TO_DATE('20190222', '%Y%m%d')
AND REG_TS < DATE_ADD('20190222', INTERVAL 1 DAY) 

AND REG_TS >= DATE_ADD('20190222', INTERVAL 0 DAY)
AND REG_TS < DATE_ADD('20190222', INTERVAL 1 DAY)

 

시작일, 종료일로 검색

select * 
from (
    select str_to_date('2023-11-13 00:00:00.000', '%Y-%m-%d %H:%i:%s.%f') reg_dt union all
    select str_to_date('2023-11-13 23:59:59.999', '%Y-%m-%d %H:%i:%s.%f') reg_dt union all
    select str_to_date('2023-11-14 00:00:00.000', '%Y-%m-%d %H:%i:%s.%f') reg_dt union all
    select str_to_date('2023-11-14 23:59:59.999', '%Y-%m-%d %H:%i:%s.%f') reg_dt union all
    select str_to_date('2023-11-15 00:00:00.000', '%Y-%m-%d %H:%i:%s.%f') reg_dt union all
    select str_to_date('2023-11-15 23:59:59.999', '%Y-%m-%d %H:%i:%s.%f') reg_dt union all
    select str_to_date('2023-11-16 00:00:00.000', '%Y-%m-%d %H:%i:%s.%f') reg_dt union all
    select str_to_date('2023-11-16 23:59:59.999', '%Y-%m-%d %H:%i:%s.%f') reg_dt union all
    select null
) a
where reg_dt is not null
and reg_dt >= str_to_date('2023-11-14', '%Y-%m-%d')
and reg_dt < date_add(str_to_date('2023-11-15', '%Y-%m-%d'), interval 1 day)
order by reg_dt desc
;

'DB > MySQL' 카테고리의 다른 글

[MySql] Database, User, AutoCommit 정보  (0) 2019.04.04
[MySQL] console 명령어  (0) 2019.01.15
[MySql] IP 주소 변환, INET_ATON, INET_NTOA  (0) 2017.10.16
[MySQL] insert all  (0) 2017.04.13
[MySQL] Bind Variables  (0) 2017.03.24
Comments