DateRange

(Date range에서 넘어옴)
DateRange

1 PHP[ | ]

PHP
Copy
class DateRange extends ArrayIterator {
	protected $oDate = null;
	protected $oStartDate = null;
	protected $oEndDate = null;
	protected $oInterval = null;

	function __construct( $strStart, $strEnd, $strInterval = 'auto' ) {
		$this->oStartDate = new DateTime($strStart);
		$this->oDate = clone $this->oStartDate;
		$this->oEndDate = new DateTime($strEnd);
		if( $strInterval == 'auto' ) $strInterval = ($strStart<$strEnd) ? '1 day' : '-1 day';
		$this->oInterval = DateInterval::createFromDateString($strInterval);
	}

	function next() {
		$this->oDate->add($this->oInterval);
		return $this->oDate;
	}

	function current() {
		return $this->oDate->format("Y-m-d");
	}

	function valid() {
		if ($this->oStartDate > $this->oEndDate) return $this->oDate >= $this->oEndDate;
		if ($this->oStartDate < $this->oEndDate) return $this->oDate <= $this->oEndDate;
		return $this->oDate == $this->oEndDate;
	}
}

$range = new DateRange("2000-01-01", "2000-01-03");
foreach($range as $date) echo $date.'<br>';
// 2000-01-01
// 2000-01-02
// 2000-01-03

$range = new DateRange("2000-01-03", "2000-01-01");
foreach($range as $date) echo $date.'<br>';
// 2000-01-03
// 2000-01-02
// 2000-01-01

$range = new DateRange("2000-01-01", "2000-03-01", "3 week");
foreach($range as $date) echo $date.'<br>';
// 2000-01-01
// 2000-01-22
// 2000-02-12

2 같이 보기[ | ]

편집자 J Jmnote Jmnote bot
  • PHP 파일 다운로드 구현 2 (한글 파일명 지원)
    제가 파일다운로드 관련된 것이 서툴러서 파일 다운로드 부분을 인용하였습니다. 죄송합니다.
  • PHP에서 오라클 DB 사용
    감사합니당. YoWu
  • PHP 파일 업로드 구현
    파일정보 출력에서 $name $ext 가 정상적으로 출력되나요? 전부 echo의 쌍따옴표안에 있는데? 일리단사오육칠
  • PHP 파일 업로드 구현
    PHP echo에서 쌍따옴표 안의 변수는 해석되어 출력됩니다. 위 소스에서도 $name와 $ext가 두껍게 나와있죠? 일반 문자열과는 다르다는 표시죠.J Jmnote
  • PHP 파일 다운로드 구현 2 (한글 파일명 지원)
    'Windows NT 6.1' << 이부분은 접속한 윈도우의 플랫폼을 뜻하는걸로 압니다. ie11 접속하면 다음과 같이 바뀌었고 Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko rv:11.0 << 이부분이 Anmkst
  • Lib my.php
    Fatal error: Uncaught Error: Call to undefined function insert_rows() in D:\xampp\htdocs\naru\import_excel.php:38 Stack trace: #0 {main} thrown in D:\xampp\htdo 신정섭
  • Lib my.php
    함수 query()를 사용하면 됩니다. 예시 추가했으니 참고바랍니다.J Jmnote
  • 로또번호 생성
    초보를 위한 개발 실습 과제로군요 ㅎㅎ Pinkcrimson