[英]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.