如何使用PHP查找一个月中的第一个和最后一个日期?例如,今天是2010年4月21日。我想找到2010年4月1日和2010年4月30日。
3 回答

慕容3067478
TA贡献1773条经验 获得超3个赞
这将为您提供该月的最后一天:
function lastday($month = '', $year = '') {
if (empty($month)) {
$month = date('m');
}
if (empty($year)) {
$year = date('Y');
}
$result = strtotime("{$year}-{$month}-01");
$result = strtotime('-1 second', strtotime('+1 month', $result));
return date('Y-m-d', $result);
}
第一天:
function firstDay($month = '', $year = '')
{
if (empty($month)) {
$month = date('m');
}
if (empty($year)) {
$year = date('Y');
}
$result = strtotime("{$year}-{$month}-01");
return date('Y-m-d', $result);
}
- 3 回答
- 0 关注
- 402 浏览
添加回答
举报
0/150
提交
取消