Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- strpos
- mb_strimwidth
- 세션
- 웹프로그래밍
- date
- 시간계산
- mysql
- 쿠키
- indexOf
- ucfirst
- 이전주소
- input
- date포맷
- Meta Tag
- attr
- php
- Javascript
- SubString
- JQuery
- HTML
- 문자열포함여부
- accept
- 세션사용법
- parent of iframe
- File
- CSS
- element추가
- Selector
- disabled
- strtotime
Archives
- Today
- Total
Heojju
[PHP] strtotime 함수 본문
strtotime 함수
int 형 함수로 날짜, 시간을 계산할 때 사용합니다.
1. 표현
<?php echo strtotime("now"), "\n"; // 현재 echo strtotime("10 September 2000"), "\n"; // 2000년 9월 10일 echo strtotime("+1 day"), "\n"; // 하루 후 echo strtotime("+1 week"), "\n"; // 일주일 후 echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n"; // 1주 2일 4시간 2초 후 echo strtotime("next Thursday"), "\n"; // 다음주 목요일 echo strtotime("last Monday"), "\n"; // 저번주 월요일 echo date( "Y-m-d", strtotime( "2009-01-31 +1 month" ) ); // PHP: 2009-02-31 ?> |
2. 날짜 간의 계산(날짜 더하기 빼기)
<?php $date = "2016-12-25"; $today = date("Y-m-d", time()); $result = ((strtotime($date) - strtotime($today))/86400); // 86400 (60초*60분*24시) echo $result."일"; ?> |
결과 값은 "19일" 이 나옵니다.
'웹개발 > PHP' 카테고리의 다른 글
[PHP] strpos() 문자열 포함 여부 확인 (0) | 2016.12.19 |
---|---|
[PHP] str_word_count() - 문자열 카운트 (0) | 2016.12.14 |
[PHP] 데이터 엑셀로 저장기능 (0) | 2016.12.09 |
[PHP] strip_tags 를 이용한 태그 삭제 (0) | 2016.11.30 |
[PHP] Date 포맷 (0) | 2016.11.30 |