date 질문드립니다.

date 질문드립니다.

QA

date 질문드립니다.

답변 1

본문


    $date_term = date('w', G5_SERVER_TIME);
    $today_date = $stx_date;
    $week_term = $date_term + 7;
    $last_term = strtotime(date('Y-m-01', G5_SERVER_TIME));
    $stx_one_start = date('Y-m-01', strtotime('-1 Month', $last_term));
    $stx_one_end =  date('Y-m-t', strtotime('-1 Month', $last_term));
    $stx_two_start = date('Y-m-01', strtotime('-2 Month', $last_term));
    $stx_two_end =  date('Y-m-t', strtotime('-2 Month', $last_term));

 

간단하게

한달전 1일 ~ 말일,

두달전 1일 ~ 말일 소스입니다.

 

$today_date 를 기준으로 한달전, 2달전을 적용할려면 어떻게 해야 하나요?

 

예를들어 $today_date가 2022-02-02 이면

한달전은 2022-01-01

두달전은 2021-12-01 이렇게 표현하고 싶습니다.

이 질문에 댓글 쓰기 :

답변 1

 

$today = '2022-02-01';

$timestamp = strtotime("{$today} -1 months"); // 한달전

$timestamp2 = strtotime("{$today} -2 months");   // 두달전

 

echo date("Y-m-d H:i:s", $timestamp); // 한달전

echo date("Y-m-d H:i:s", $timestamp2); // 두달전

 

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
filter #php ×
  • 질문이 없습니다.
전체 0
© SIRSOFT
현재 페이지 제일 처음으로