[英]PHP get start and end date of a week from selected months
I want to get start and end date of a week from Month but I have no idea how can I do that please help me thanks我想从月份获得一周的开始和结束日期,但我不知道该怎么做,请帮助我谢谢
return request退货请求
array:3 [▼
0 => "Jan"
1 => "Feb"
2 => "Mar"
]
controller controller
if ($request->options == "Week") {
$months = array('Dec','Jan','Feb');
$dto = new DateTime();
$dto->setISODate("2021", date('W',strtotime('2021-12-01')));
$ret['week_start'] = $dto->format('Y-m-d');
$dto->modify('+6 days');
$ret['week_end'] = $dto->format('Y-m-d');
return $ret;
}
Use this library for date/time management in PHP via composer:通过 composer 在 PHP 中使用此库进行日期/时间管理:
composer require nesbot/carbon
https://github.com/briannesbitt/Carbon https://github.com/briannesbitt/Carbon
echo Carbon::create(2014, 5, 30, 0, 0, 0)->firstOfMonth(); // 2014-05-01 00:00:00
echo Carbon::create(2014, 5, 30, 0, 0, 0)->firstOfMonth(Carbon::MONDAY); // 2014-05-05 00:00:00
echo Carbon::create(2014, 5, 30, 0, 0, 0)->lastOfMonth(); // 2014-05-31 00:00:00
echo Carbon::create(2014, 5, 30, 0, 0, 0)->lastOfMonth(Carbon::TUESDAY); // 2014-05-27 00:00:00
echo Carbon::create(2014, 5, 30, 0, 0, 0)->nthOfMonth(2, Carbon::SATURDAY); // 2014-05-10 00:00:00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.