Get week number in month from date in PHP?

前端 未结 14 2226
说谎
说谎 2020-11-28 11:15

I have an array of random dates (not coming from MySQL). I need to group them by the week as Week1, Week2, and so on upto Week5.

What I have is this:



        
14条回答
  •  伪装坚强ぢ
    2020-11-28 11:54

    //It's easy, no need to use php function
    //Let's say your date is 2017-07-02
    
    $Date = explode("-","2017-07-02");
    $DateNo = $Date[2];
    $WeekNo = $DateNo / 7; // devide it with 7
    if(is_float($WeekNo) == true)
    {
       $WeekNo = ceil($WeekNo); //So answer will be 1
    }  
    
    //If value is not float then ,you got your answer directly
    

提交回复
热议问题