[英]The first day and the last day of the month
有人可以幫助我嗎,我需要獲取以下值:
$startTime
必須是一個月的第一天,且為00:00:00
,否則
無效時間
$_GET
end_date
必須始終是時間為00:00:00
的一個月的第一天,否則invalid date
$defaultEndTime
必須是當前月份的第一天,時間為00:00:00
$endTime
必須是一個月的第一天, $endTime
00:00:00
,否則
無效時間
$startTime
和$endTime
之間的差值必須恰好是一個月
我試過了:
$end_date=new DateTime();
$end_date->format('Y-m-js 00:00:00');
我嘗試使用datedif
獲取不同的startTime
end endTime
但我不知道如何獲得一個月。
獲取每月的第一天和最后一天
$date = '2018-01-11';
// First day with 00:00:00
echo date('Y-m-01 00:00:00', strtotime($date ));
echo '<br>';
// Last day with 00:00:00
echo date('Y-m-t 00:00:00', strtotime($date ));
輸出:
2018-01-01 00:00:00
2018-01-31 00:00:00
=>嘗試這段代碼。
<?php
echo date("Y-m-d 00:00:00", strtotime('first day of this month'));
echo "<br/>";
echo date("Y-m-d 00:00:00", strtotime('last day of this month'));
?>
演示:-https: https://eval.in/933378
$startDate = date('01-m-Y 00:00:00',strtotime('this month')); // First day of current month
echo $startDate;
$endDate = date("t-m-Y 00:00:00", strtotime($startDate ));// Last date of current month.
//'t' provide last day of month means if, it is Jan then get 31
//and also if current month is Feb then t provide 28.It's happend same as other months.
echo $endDate ;
Lets Today是11-01-2018。 然后輸出:
01-01-2018 00:00:00
31-01-2018 00:00:00
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.