-6

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

user3603789
  • 50
  • 1
  • 9
  • 3
    "*please do not give me static solution.*" — That's not how the site works. We don't write code for you, we only help you write it. Show us what you've tried so far. – Amal Murali May 05 '14 at 11:47
  • Are the dates dateTime objects or timestamps or ..? – Naruto May 05 '14 at 11:48
  • @Naruto I have only start date and from that start date i have to find n occurrence of weekday. date format should be like year-month-date – user3603789 May 05 '14 at 11:50
  • possible duplicate of [Get all occurrence of specific day in a month](http://stackoverflow.com/questions/23469816/get-all-occurrence-of-specific-day-in-a-month) – gnat Jun 29 '14 at 14:25

1 Answers1

0

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'));
}
pah
  • 4,700
  • 6
  • 28
  • 37
  • You can still use the strtotime() to do that. Please refer to the documentation in the first link of the answer. – pah May 05 '14 at 12:01
  • Also what you're asking may be a duplicate of this: http://stackoverflow.com/questions/2784484/how-to-find-nearest-day-of-week-in-php – pah May 05 '14 at 12:03
  • I'm not asking anything, the guy who asked the question did.. :) – Naruto May 05 '14 at 12:06
  • Note that I answered your exact question. The Friday occurence part you're looking for is in the posted stackoverflow link. – pah May 05 '14 at 12:09