반응형
주어진 달의 첫날과 마지막 날을 얻는 방법
월 () 및 year () 함수를 사용하여 내 함수에 'Ymd'매개 변수 형식으로 이동하는 특정 월의 모든 게시물을 표시하는 mysql 쿼리를 다시 작성하고 싶지만 어떻게 얻을 수 있는지 모르겠습니다. 주어진 달 날짜의 마지막 날.
$query_date = '2010-02-04';
list($y, $m, $d) = explode('-', $query_date);
$first_day = $y . '-' . $m . '-01';
strtotime및 date기능 을 살펴볼 수 있습니다 .
<?php
$query_date = '2010-02-04';
// First day of the month.
echo date('Y-m-01', strtotime($query_date));
// Last day of the month.
echo date('Y-m-t', strtotime($query_date));
이 질문에 't'로 좋은 대답이 있다는 것을 알고 있지만 다른 해결책을 추가 할 것이라고 생각했습니다.
$first = date("Y-m-d", strtotime("first day of this month"));
$last = date("Y-m-d", strtotime("last day of this month"));
PHP 5.3 이상을 사용하는 경우 PHP에서 시도하십시오.
$query_date = '2010-02-04';
$date = new DateTime($query_date);
//First day of month
$date->modify('first day of this month');
$firstday= $date->format('Y-m-d');
//Last day of month
$date->modify('last day of this month');
$lastday= $date->format('Y-m-d');
다음 달의 마지막 날짜를 찾으려면 다음과 같이 수정하십시오.
$date->modify('last day of 1 month');
echo $date->format('Y-m-d');
등등..
cal_days_in_month () 는 해당 월의 총 일수, 따라서 마지막 일수를 제공해야합니다.
원래:
$lastDate = date("Y-m-t", strtotime($query_d));
날짜 t 매개 변수는 현재 달의 일 수를 반환합니다.
// First date of the current date
echo date('Y-m-d', mktime(0, 0, 0, date('m'), 1, date('Y')));
echo '<br />';
// Last date of the current date
echo date('Y-m-d', mktime(0, 0, 0, date('m')+1, 0, date('Y')));
$month = 10; // october
$firstday = date('01-' . $month . '-Y');
$lastday = date(date('t', strtotime($firstday)) .'-' . $month . '-Y');
이번 달 주만 인쇄 :
function my_week_range($date) {
$ts = strtotime($date);
$start = (date('w', $ts) == 0) ? $ts : strtotime('last sunday', $ts);
echo $currentWeek = ceil((date("d",strtotime($date)) - date("w",strtotime($date)) - 1) / 7) + 1;
$start_date = date('Y-m-d', $start);$end_date=date('Y-m-d', strtotime('next saturday', $start));
if($currentWeek==1)
{$start_date = date('Y-m-01', strtotime($date));}
else if($currentWeek==5)
{$end_date = date('Y-m-t', strtotime($date));}
else
{}
return array($start_date, $end_date );
}
$date_range=list($start_date, $end_date) = my_week_range($new_fdate);
## Get Current Month's First Date And Last Date
echo "Today Date: ". $query_date = date('d-m-Y');
echo "<br> First day of the month: ". date('01-m-Y', strtotime($query_date));
echo "<br> Last day of the month: ". date('t-m-Y', strtotime($query_date));
참고URL : https://stackoverflow.com/questions/7541938/how-to-get-the-first-and-last-days-of-a-given-month
반응형
'Nice programing' 카테고리의 다른 글
| XPath로 Java의 네임 스페이스를 사용하여 XML을 쿼리하는 방법은 무엇입니까? (0) | 2020.11.29 |
|---|---|
| 디버깅하는 동안 iOS 애플리케이션 샌드 박스에서 파일의 내용을 볼 수 있습니까? (0) | 2020.11.29 |
| Bash에서 작은 따옴표 문자열에서 작은 따옴표를 이스케이프하는 방법은 무엇입니까? (0) | 2020.11.29 |
| Java 8에서 여러 필드 이름으로 그룹화 (0) | 2020.11.29 |
| Vue @click 이벤트 핸들러에 매개 변수를 전달하는 방법 (0) | 2020.11.29 |