doudizhu2222 2016-03-11 15:05
浏览 242
已采纳

获取当前年份的开始和结束日期时发出

I searched a lot on Google to get the start and end date of the current year. Now, After 2 hours of search, posted the query here.

Below is what i have tried so far. but not working.

$date = date('Y-m-d');
$startDate = new \DateTime($date);
$endDate = new \DateTime($date);
$endDate->modify("+1 day -1 second");

can you please guide me in right direction ?

  • 写回答

1条回答 默认 最新

  • duanquan4451 2016-03-11 15:33
    关注

    To get the start date: date('Y-01-01') and end date date('Y-12-31').

    If you use Carbon, to get the weekdays:

    $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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥15 this signal is connected to multiple drivers怎么解决
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus