获取当前年份的开始和结束日期时发出
Issue while getting start and end date of current Year
我在 Google 上搜索了很多,以获取当年的开始和结束日期。
现在,经过 2 小时的搜索,在此处发布查询。
以下是我到目前为止尝试过的方法。但不工作。
$date = date('Y-m-d');
$startDate = new \DateTime($date);
$endDate = new \DateTime($date);
$endDate->modify("+1 day -1 second");
你能指导我正确的方向吗?
获取开始日期:date('Y-01-01')
和结束日期 date('Y-12-31')
。
如果您使用 Carbon,获取工作日:
$year = date('Y');
$date = Carbon::create($year, 12, 31, 0, 0, 0);
$date->toDateTimeString($year, 12, 31, 0, 0, 0); // 2016-12-31 00:00:00
$date->format('l'); // Saturday
$date2 = Carbon::create($year, 1, 1, 0, 0, 0);
$date2->toDateTimeString($year, 1, 1, 0, 0, 0); // 2016-01-01 00:00:00
$date2->format('l'); // Firday
我在 Google 上搜索了很多,以获取当年的开始和结束日期。 现在,经过 2 小时的搜索,在此处发布查询。
以下是我到目前为止尝试过的方法。但不工作。
$date = date('Y-m-d');
$startDate = new \DateTime($date);
$endDate = new \DateTime($date);
$endDate->modify("+1 day -1 second");
你能指导我正确的方向吗?
获取开始日期:date('Y-01-01')
和结束日期 date('Y-12-31')
。
如果您使用 Carbon,获取工作日:
$year = date('Y');
$date = Carbon::create($year, 12, 31, 0, 0, 0);
$date->toDateTimeString($year, 12, 31, 0, 0, 0); // 2016-12-31 00:00:00
$date->format('l'); // Saturday
$date2 = Carbon::create($year, 1, 1, 0, 0, 0);
$date2->toDateTimeString($year, 1, 1, 0, 0, 0); // 2016-01-01 00:00:00
$date2->format('l'); // Firday