Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Finding the 12th Business Day of a Month
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00426013
Message ID:
00426198
Views:
22
>>>I have the need to find the 12th business day of the month. I am not sure how to go about skipping the weekends in order to figure this out. Come to think of it I'll probably have to deal with holidays as well...uuuggggghhhhh!!! Can anyone with more brains than me point me in the right direction?

>>I'd just initialize a business-day counter, start at day one, move forward keeping track of the counter and Saturday & Sunday and when you get to #12 stop.
>>For the holidays you can have a second table and check it.
>>Several years back I wrote a bank holiday program but I don't know where it is now.. Sorry... But, it is do-able.

I'm not so hot on U.S. holidays - I'm guessing Thanks Giving below! But if you have the same holidays in the U.S. either side of Easter as we do in the U.K. then you will probably find the following useful. I've tested for 12 months of this year and it looks OK. If someone can let me know when the U.S. holidays are I could incorporate the fix and add this to the files section - if anyone thinks it is worth it.
Regards,
Houston.
FOR iMonth = 1 TO 12
   *--- iMonth = MONTH( DATE() )
   iBusDay12 = FindBusinessDay( 12, iMonth )
   ? TTOD( DATETIME( YEAR( DATE( )), iMonth, iBusDay12 ))
NEXT iMonth

RETURN .T.

****************************************************
FUNCTION FindBusinessDay( iTargetDay, iTargetMonth )
****************************************************
   LOCAL iBusinessDays, iCurrentYear, iDay
   LOCAL ARRAY aHolidays[ 7 ]

   #DEFINE FRIDAY             6

   #DEFINE NEW_YEAR           1
   #DEFINE EASTER_FRIDAY      2
   #DEFINE EASTER_MONDAY      3
   #DEFINE INDEPENDANCE_DAY   4
   #DEFINE THANKS_GIVING      5
   #DEFINE CHRISTMAS_DAY      6
   #DEFINE BOXING_DAY         7

   iCurrentYear = YEAR( DATE())

   aHolidays[ NEW_YEAR ]         = TTOD( DATETIME( iCurrentYear, 1, 1 ))
   aHolidays[ EASTER_FRIDAY ]    = fEaster( iCurrentYear ) - 2
   aHolidays[ EASTER_MONDAY ]    = fEaster( iCurrentYear ) + 1
   aHolidays[ INDEPENDANCE_DAY ] = TTOD( DATETIME( iCurrentYear, 7, 4 ))
   aHolidays[ THANKS_GIVING ]    = TTOD( DATETIME( iCurrentYear, 10, 23 ))
   aHolidays[ CHRISTMAS_DAY ]    = TTOD( DATETIME( iCurrentYear, 12, 25 ))
   aHolidays[ BOXING_DAY ]       = TTOD( DATETIME( iCurrentYear, 12, 26 ))

   *- If any holidays fall on a weekend then they will need to be fixed.

   DO WHILE INLIST( CDOW( aHolidays[ NEW_YEAR ] ), "Saturday", "Sunday" )
      aHolidays[ NEW_YEAR ] = aHolidays[ NEW_YEAR ] + 1
   ENDDO

   DO WHILE INLIST( CDOW( aHolidays[ INDEPENDANCE_DAY ] ), "Saturday", "Sunday" )
      aHolidays[ INDEPENDANCE_DAY ] = aHolidays[ INDEPENDANCE_DAY ] + 1
   ENDDO

   DO WHILE INLIST( CDOW( aHolidays[ THANKS_GIVING  ] ), "Saturday", "Sunday" )
      aHolidays[ THANKS_GIVING  ] = aHolidays[ THANKS_GIVING  ] + 1
   ENDDO

   DO WHILE INLIST( CDOW( aHolidays[ CHRISTMAS_DAY ] ), "Saturday", "Sunday" )
      aHolidays[ CHRISTMAS_DAY ] = aHolidays[ CHRISTMAS_DAY ] + 1
   ENDDO

   IF DOW( aHolidays[ CHRISTMAS_DAY  ] )
censored.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform