douying0108 2014-05-05 11:45
浏览 68
已采纳

得到n个工作日

I need 4 occurrence of Friday with date. Start date from 2014-05-25

Following will be the answer in this case.

2014-05-30
2014-06-06
2014-06-13
2014-06-20

There can be n occurrence of specific weekday and i need solution purely in PHP not in mysql

  • 写回答

1条回答 默认 最新

  • douzhongju8780 2014-05-05 11:51
    关注

    Take a look into this.

    You can do something like:

    strtotime("+1 week", timestamp);
    

    Where timestamp is the UNIX timestamp for the start date. You can replace 1 with a variable, and by using a loop you can write a generic function.

    Hope this helps.

    Edit #1:

    Also, you can recur to strtotime() to generate your timestamp:

    strtotime("+1 week", strtotime('2014-05-30'));
    

    A possible whole solution would be (untested code):

    for ($i = 1; $i <= 4; $i ++) {
       strtotime("+" . $i . " week", strtotime('2014-04-25'));
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?