First date of a week

后端 未结 4 1120
深忆病人
深忆病人 2021-01-06 13:49

I want a First Day Of a week say I have 45th week. Now I want to have date of the first sunday of this week. Can any one suggest me how I can go about this ?

Thank

4条回答
  •  半阙折子戏
    2021-01-06 14:09

    If you have the month, day and year:

    $timestamp = mktime(0, 0, 0, $month, $day, $year);
     echo date('c', $timestamp) = mktime(0, 0, 0, $month, date('d', $timestamp)-date('w', $timestamp), $year);
    

    you could also do it this way if you have the timestamp:

    echo $date('c', mktime(0, 0, 0, $month, date('d', $timestamp)-date('w', $timestamp), $year));
    

    From: http://pinoytech.org/blog/post/get-the-first-day-of-the-week-with-an-exact-date

提交回复
热议问题