Re: Brilliance requested - calculating a date next month [message #174453 is a reply to message #174450] |
Sun, 12 June 2011 19:46 |
Michael Fesser
Messages: 215 Registered: September 2010
Karma:
|
Senior Member |
|
|
.oO(bill)
> I am quietly banging my head on the wall. In concept it seems so
> simple:
>
> I need to calculate the date of an appointment next month.
> but:
> it needs to be on the same day of the month,
> eg: from the 2nd Tuesday of this month to the 2nd Tuesday of
> next month.
>
> obviously this will not work the 5th week of any month, so we can
> limit it to the first 4 weeks of the "from" month (but this is
> not the same as the first 28 days- for example January of this
> year starts on a Saturday so the first "week" is only Jan 1. The
> 2nd "week" is Jan 2..8, the third "week" is Jan 9..15).
>
> I was hoping that php would have a nifty dateTime function to do
> this, but I can't find one: I checked out dateInterval and the
> various date functions.
>
> Right now I am so brain locked that I can't even figure out how
> to calculate which week of the month is the first date.
Not a solution, just some thoughts:
You don't have to know which week you're in. It should be enough to know
which Tuesday it is. Simply spoken you just have to count backwards in
steps of 7 until the result becomes zero or negative. With some thoughts
this should also be possible with some modulo operation or so.
Then, if you know that for example it's the 3. Tuesday, you can use
strtotime() to figure out the first Tuesday of the next month. Maybe it
even allows to directly get the 3rd Tuesday, but if not, you just add
3-1=2 weeks and you're done.
As said - just some quick thoughts.
HTH
Micha
|
|
|