How to find Find First Sunday of every month

前端 未结 4 878
陌清茗
陌清茗 2020-12-22 14:15

I have require first sunday date of every month using php code.

please can help me.

getSunday();
相关标签:
4条回答
  • 2020-12-22 14:39

    This is the best way to get first Sunday of the month

    echo date("Y-m-d", strtotime("first Sunday of ".date('M')." ".date('Y').""));
    
    0 讨论(0)
  • 2020-12-22 14:42

    You can use the Date/Time extension.

    $start    = new DateTime('2012-12-31');
    $end      = new DateTime('2013-12-31');
    $interval = DateInterval::createFromDateString('first sunday of next month');
    $period   = new DatePeriod($start, $interval, $end, DatePeriod::EXCLUDE_START_DATE);
    foreach($period as $time) {
        echo $time->format("F jS") . "<br>\n";
    }
    /*
    January 6th 
    February 3rd 
    March 3rd 
    April 7th 
    May 5th 
    June 2nd 
    July 7th 
    August 4th 
    September 1st 
    October 6th 
    November 3rd 
    December 1st
    */
    
    0 讨论(0)
  • 2020-12-22 14:44
    function firstSunday($DATE)
        {
            $date = strftime("%Y-%m",$DATE);
            $day = trim(strftime("%e",$DATE));
    
            for($day; $day <= '7'; $day++){
                $dd = strftime("%A",strtotime($date.'-'.$day));
                if($dd == 'Sunday'){
                    return strftime("%Y-%m-%d",strtotime($date.'-'.$day));
                }
            }
        }
    
    0 讨论(0)
  • 2020-12-22 14:51

    I was looking for the DTS dates so here's how I found them:

    $dtsStart = date('Y-m-d 02:00:00', strtotime('Second Sunday Of March 2015'));
    $dtsEnd = date('Y-m-d 02:00:00', strtotime('First Sunday Of November 2015'));
    
    0 讨论(0)
提交回复
热议问题