FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Brilliance requested - calculating a date next month
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Brilliance requested - calculating a date next month [message #174471 is a reply to message #174453] Mon, 13 June 2011 10:46 Go to previous messageGo to previous message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma:
Senior Member
On 6/12/2011 3:46 PM, Michael Fesser wrote:
> .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.

Starting with this bit of Brilliance, it suddenly came to me that
the first Monday, first Tuesday, etc., all happen to occur in the
first 7 days of each month. Likewise the second MOnday, etc. all
occur in days 8-14.
So, (as yet untested)
If the current appointment is on a Tuesday
$Nmonth = next month // range 1-12
$NYear = next year
$day = current day of the month // limited to a range of 1-28
$week = floor($day/7); //range 0-4)

in the next month
$start = strtotime($NYear. "-" . $Nmonth . "-" . ($week * 7) -1))
$nextAppt = strtotime ("next Tuesday", $start)

This will require some tweaking for the first two days of the
month, obviously

bill
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Strategic HR Summit 2011 (Jun 25, Mumbai)
Next Topic: MySQL's PASSWORD() function
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Dec 24 18:39:05 GMT 2024

Total time taken to generate the page: 0.04054 seconds