[PHP] DateTime:: Unexpected character 에러 해결하기
·
Development/PHP
DateTime::__construct(): Failed to parse time string ( 13 March 2023) at position 0 (�): Unexpected character 사용한 코드는 아래와 같다. 날짜 변환함수를 사용하는데, 위와 같은 에러가 발생하였다. try { $strCommentDate = new DateTime($strCommentDate); } catch(Exception $e) { echo $e->getMessage(); } 예기치 않은 문자(인쇄할 수 없거나 인식할 수 없는 문자)가 포함되어있어서 실패하게 된 것이다. 다른 여러 방법들도 있겠지만, 정규식을 통해 해결하였다. preg_replace('/[^\x20-\x7E]/', '', $text); 위 정규식은..
[MySql] DATETIME 값 수정하기(update)
·
Development/MySql
DATETIME 바꾸고 싶은 날짜를 형식에 맞게 텍스트로 업데이트 하면 된다. 0000-00-00 00:00:00 update 테이블명 set date = "2023-01-26 00:00:00"
date 조회 시 유의사항
·
Development/MySql
날짜 조회하다가, 늘 쓰던 between A and B를 사용하였는데 특정 날짜가 안나왔다. 상황 between A and B 사용 where date between '2021-10-01' and '2021-12-31' where date between '2021-10-01' and '2021-12-31' 이렇게 입력했더니 2021-10-01~2021-12-30 일자만 출력 되었다.. where date_format(sd_date,'%Y%m%d')=20211231 분명 조회했을땐 데이터가 있었는데 안나오길래 찾아본결과, 해당 date 칼럼은 datetime 형식으로, 내가 조회할때 시간을 입력하지 않아서 자동으로 00:00:00으로 된 것이다. 그래서 실제로 조회할때의 값은 2021-10-01 00:00..
날짜변환
·
Development/PHP
날짜를 변환하고 싶을 때 아래 처럼 해주면 된다. 기본 try { $strDate = new DateTime($strDate); } catch(Exception $e) { echo" \n 날짜변환 오류"; } $strDate = @date_format($strDate, 'Y-m-d'); @date_format 에서 원하는 양식으로 날짜를 변환할 수 있다. Y-m-d로 변환하면 2022-06-30이 나오게 된다. ex. Y.m.d => 2022.06.30 / Ymd => 20220630 / ymd => 220630 ... # 2021-12-22T11:00:44+00:00 # 2021-12-22T11:00:44+00:00 // 1 $strDate = explode('+', $strDate[1]); $strD..