|
|
|||||||
Dear guruz, I'd like to implement a date based if condition. I would like my condition to be true if the current date is equal to the second business day (jour ouvré in French). I really don't know how to implement such a test. Many thanks for your help. SRoux |
||||||||
|
|
|||||||
Hi SRoux, do you mean a workday? i.e. Monday to Friday ? Or the second workday, which may be Tuesday ? @day will give you the day of the week. @wdayno will give days since Sunday Or is there some other translation/meaning to this phrase ? Regards, Bill |
||||||||
|
|
|||||||
A quick and dirty way would be something liek this. The downside of this quick and drity fix is that you need to enter all second workday dates. Code: $dates = "2009/01/02","2009/02/03","2009/03/03","2009/04/02","2009/05/05","2009/06/02" + "2009/07/02","2009/08/04","2009/09/02","2009/10/02","2009/11/03","2009/12/02" If AScan($dates, @DATE) ;Do stuff Else ;Do nothing EndIf |
||||||||
|
|
|||||||
I think indeed that the best solution is to manage it through a quick and dirty script as I tried the following but its non sense! Code: $bday = "monday", "tuesday", "wednesday", "thursday", "friday" If AScan($bday, @Day) ; Business day/Workday If @MDayNo = 2 ;That is false ; Business day/Workday ? "2nd business day : @Day - @MDayNo - @Date" Else ? "not 2nd business day : @Day - @MDayNo - @Date" Endif Else ? "not a business day / workday : @Day - @MDayNo - @Date" Endif |
||||||||
|
|
|||||||
how about Code: If @WDAYNO = 3 ; it's Tuesday! Else If @WDAYNO = 1 or @WDAYNO = 7 ; It's a WEEKEND! Else ; It's a workday, but not the SECOND workday EndIf EndIf Glenn |
||||||||
|
|
|||||||
Quote: This covers all options, no? Unless the OP means the second working day of the month. Sroux, could you explain exactly what "second business day" means? Maybe give an example. It might be simplest to follow Mart's example and set up a calendar for each year so you can deal with local holidays. |
||||||||
|
|
|||||||
I based my reply on the fact that the OP created an array called "$BD" (BusinessDay), and the lack of any holiday-type logic in his code. Holidays aside, if we're looking for the second business day of the month, it's pretty limited logic - it can only be the second, through the fourth, depending on whether the first is on a Friday/weekend or not. If the first was a Friday, the second day is Monday following, If the first is on Saturday, or Sunday, the second business day is the Tuesday that follows. Otherwise, it is the second day of the month. Thus, Code: Select ; First was Friday - SBD is Monday Case @WDAYNO = 2 And @MDAYNO = 4 DoSecondBusDay() ; First was Sat or Sun - SBD is Tuesday Case @WDAYNO = 3 And @MDAYNO = 4 or @MDAYNO = 3 DoSecondBusDay() ; First is Mon-Thur, today is the second day of the month Case @MDAYNO = 2 DoSecondBusDay() EndSelect Code: [SBD_OF_MONTH] 2009/01/02=1 2009/02/03=1 2009/03/03=1 2009/04/02=1 Code: If ReadProfileString('.\dates.ini', 'SBD_OF_MONTH', @DATE) ; it's the second business day! EndIf Glenn |
||||||||
|
|
|||||||
Just a quick note on what @wdayno returns. It returns the number of days since Sunday, so for Tuesday it returns 2 Today is Thursday so it returns 4. Best wishes, |