简体   繁体   English

PHP 从选定月份中获取一周的开始和结束日期

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

相关问题 从 PHP 中的日期范围获取一周的开始和结束日期 - Get start and end date of a week from date range in PHP PHP按周数获取一周的开始和结束日期 - PHP get start and end date of a week by weeknumber 如何获得给定的月数(星期数),也从星期一开始,直到星期五。 以及整个星期的开始日期和结束日期 - How to Get The Given Months Number of Weeks and also week start from monday and end with friday. and also all week start date and end date 如何在 php 中获取给定日期范围的月份的开始日期和结束日期 - How to get start and end date of months of a given range of date in php php,根据开始日期和月数获取结束日期 - php, get an end date based on start date and number of months PHP获取特定年份的52周开始/结束日期 - PHP Get 52 week start/end date for a specific year 通过PHP中月份的星期数获取月份的开始和结束日期 - get start and end date of month by week number of the month in php 如何在php中获取周日开始日期和周日结束日期 - How to get week start date Sunday and week end date Saturday in php 当周数可用时,如何从MYSQL获取一周的“开始日期”和“结束日期”? - How to get “start date” and “end date” of a week from MYSQL when week number is available? 根据字符串获取星期的开始和结束日期 - Get Start and end date of Week according to string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM