Page 1 of 1 1
Topic Options
#196488 - 2009-10-27 02:19 PM business day based test
sroux Offline
Fresh Scripter

Registered: 2009-06-01
Posts: 6
Loc: France
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

Top
#196490 - 2009-10-27 03:57 PM Re: business day based test [Re: sroux]
BillBarnard Offline
Starting to like KiXtart

Registered: 2007-03-14
Posts: 141
Loc: Leighton Buzzard, Bedfordshire...
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
_________________________
Bill

Top
#196491 - 2009-10-27 04:06 PM Re: business day based test [Re: sroux]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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


Edited by Mart (2009-10-27 04:07 PM)
Edit Reason: Removed long line.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#196493 - 2009-10-27 04:48 PM Re: business day based test [Re: Mart]
sroux Offline
Fresh Scripter

Registered: 2009-06-01
Posts: 6
Loc: France
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

Top
#196495 - 2009-10-27 05:29 PM Re: business day based test [Re: sroux]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
This covers all options, no?

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#196502 - 2009-10-28 09:11 AM Re: business day based test [Re: Glenn Barnas]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
 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.

Top
#196505 - 2009-10-28 11:48 AM Re: business day based test [Re: Richard H.]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
Of course, if holidays must be accounted for, than a simple 12-line INI file would get the job done.
 Code:
[SBD_OF_MONTH]
2009/01/02=1
2009/02/03=1
2009/03/03=1
2009/04/02=1
lists the dates that represent the second business day each month. The value is unimportant, it just holds a non-zero value. The code is reduced to
 Code:
If ReadProfileString('.\dates.ini', 'SBD_OF_MONTH', @DATE)
  ; it's the second business day!
EndIf
The code will return false unless the current date is found in the dates.ini file. Of course, you could use a combination of methods, using the lookup as the first attempt in the Select statement. This way, the dates.ini file only holds holiday exceptions, which are more difficult (but not impossible) to calculate.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#196520 - 2009-10-29 05:34 PM Re: business day based test [Re: Glenn Barnas]
BillBarnard Offline
Starting to like KiXtart

Registered: 2007-03-14
Posts: 141
Loc: Leighton Buzzard, Bedfordshire...
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,
_________________________
Bill

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.057 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org