Carbon - get first day of month

前端 未结 2 605
囚心锁ツ
囚心锁ツ 2020-12-29 19:18

I am using carbon but trying to get the first day of the month so I can run a report from the beginning of the month till the current day.

    $date = [
             


        
相关标签:
2条回答
  • 2020-12-29 19:43

    Try as

    $start = new Carbon('first day of this month');
    

    CARBON DOCS Refer #Testing Aids

    If you already have Carbon object and want to find first day of month for that object you can try as,

    $startDate = Carbon::now(); //returns current day
    $firstDay = $startDate->firstOfMonth();  
    
    0 讨论(0)
  • 2020-12-29 19:57

    You can use following function

    $start = Carbon::now()->startOfMonth();
    $end = Carbon::now();
    
    0 讨论(0)
提交回复
热议问题