0

I have a date, let's say 2016-01-20 00:00:00. I want to add 1 month to the date, but not in the way that will end me up with 2016-02-20 00:00:00, instead I want it to be on month later on the same week day so basically 2016-02-17 00:00:00.

How can I do that?

EDIT: I basically want it to do the same thing as google calendar can, where you can select, when adding a new date and setting on repeat, you can select either repeat on the 4th monday or repeat on the 26th of that month. I want to know how i can do the first option to a date

NMLcygni
  • 61
  • 1
  • 7
  • you can add 28 days :) Simple. – Ali Zia Jan 26 '16 at 11:51
  • 1
    What would you want to do if the starting date was January 1st? Would you want the date to be moved *later* to the first matching week day in February, or *earlier* to the last matching week day in January? You need to make sure you've got all the rules very clearly specified - with appropriate tests. – Jon Skeet Jan 26 '16 at 11:53
  • Yeah this is just an idea. The concept must be cleared before asking. – Ali Zia Jan 26 '16 at 11:54
  • What i would like to do is find out for example this is the 3rd wednesday in this month, so the new date will also be the 3rd wednesday of that month – NMLcygni Jan 26 '16 at 12:24
  • Possible duplicate of [PHP get next occurrence of Monday from a certain date (with time)](http://stackoverflow.com/questions/22055935/php-get-next-occurrence-of-monday-from-a-certain-date-with-time) – Blackbam Jan 26 '16 at 13:17
  • What do you want if the base date is the 5th weekday of the month and the following month doesn't have 5 of those weekdays (it never does)? E.g. What is 2016-01-29 + a month? This is the 5th Friday in Jan 2016. You might want the last (4th) Friday in Feb 2016, or you might want the first Friday in Mar 2016, or you might want to declare an error. All are reasonable answers. Or perhaps you want to add a month to the *last* Friday of Jan 2016? This has a definite answer (the *last* Friday of Feb 2016). – Howard Hinnant Jan 27 '16 at 02:57

0 Answers0