PHP 날짜 시간 더하기 빼기 함수 strtotime date time
페이지 정보
작성자 관리자 (114.♡.85.207) 작성일 16-04-11 22:23 조회 10,735 댓글 0본문
strtotime
(PHP 4, PHP 5, PHP 7)
strtotime — Parse about any English textual datetime description into a Unix timestamp
설명 ¶
int strtotime ( string $time [, int $now = time() ] )
Example
[code]
<?php
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>
[/code]
[code]
<?php
//아래 함수들의 output 은 timestamp 형태의 숫자이다.
echo time();
echo strtotime("now");
echo strtotime("+1 hour");
// 아래 함수의 output 은 사람이 보기 쉬운 string 형태이다.
echo date( 'Y-m-d H:i:s', time() ); // YYYY-mm-dd HH:ii:ss
?>
[/code]
[code]
<?php
// 특정 날짜를 기준으로 날짜 더하고 빼기
$prev_date = date("Y-m-d", strtotime(date("Y-m-d") . " -1 days")); // 하루전 날자
$next_date = date("Y-m-d", strtotime(date("Y-m-d") . " +1 days")); // 하루후 날자
// 위 date("Y-m-d") 자리에 "2010-10-10" 이런식으로 넣어도 된다.
$start_date = date("Y-m-d", strtotime(date("Y-m-d") . " -3 month")); // 3달전
$start_date = date("Y-m-d", strtotime(date("Y-m-d") . " -7 year")); // 7년전
?>
[/code]
그러니까, strtotime 과 date 함수만 잘 활용하면, 다 해 먹을 수 있다. ^^
(PHP 4, PHP 5, PHP 7)
strtotime — Parse about any English textual datetime description into a Unix timestamp
설명 ¶
int strtotime ( string $time [, int $now = time() ] )
Example
[code]
<?php
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>
[/code]
[code]
<?php
//아래 함수들의 output 은 timestamp 형태의 숫자이다.
echo time();
echo strtotime("now");
echo strtotime("+1 hour");
// 아래 함수의 output 은 사람이 보기 쉬운 string 형태이다.
echo date( 'Y-m-d H:i:s', time() ); // YYYY-mm-dd HH:ii:ss
?>
[/code]
[code]
<?php
// 특정 날짜를 기준으로 날짜 더하고 빼기
$prev_date = date("Y-m-d", strtotime(date("Y-m-d") . " -1 days")); // 하루전 날자
$next_date = date("Y-m-d", strtotime(date("Y-m-d") . " +1 days")); // 하루후 날자
// 위 date("Y-m-d") 자리에 "2010-10-10" 이런식으로 넣어도 된다.
$start_date = date("Y-m-d", strtotime(date("Y-m-d") . " -3 month")); // 3달전
$start_date = date("Y-m-d", strtotime(date("Y-m-d") . " -7 year")); // 7년전
?>
[/code]
그러니까, strtotime 과 date 함수만 잘 활용하면, 다 해 먹을 수 있다. ^^
추천0
댓글목록 0
등록된 댓글이 없습니다.