Alpha Video Training
Results 1 to 12 of 12

Thread: add_bus_days(month_start(date()),1) Ending Date Results?

  1. #1
    Member
    Real Name
    Reed Orbs
    Join Date
    Oct 2005
    Posts
    59

    Default add_bus_days(month_start(date()),1) Ending Date Results?

    What should be the results of this combination function add_bus_days(month_start(date()),1) Using the first day of each month for the year 2006?

    Ending_Date = ADD_BUS_DAYS( Starting_Date as D, Add_Days as N [, Ignore_Holiday_Flag as C [, Holiday_Table as C ]] )

    My Diagnostics shows incrementing the Add_Days by 1 for each of the 1-20 some work days in a month works except for when the first day of the month starts on a week-end then the Ending_Date is incorrect.

    For the year 2006 I found the following; for Stating_Date being changed manually for the first day of the month (01/01/2006) or by changing the computer date for the first of each month using (month_start) both were the same results.

    (The asterisks show the incorrect months with double asterisks showing also incorrect holliday calculation )

    Starting_Date 01/01/2006 the result for Ending_Date = 01/02/2006
    Starting_Date 02/01/2006 the result for Ending_Date = 02/02/2006*
    Starting_Date 03/01/2006 the result for Ending_Date = 03/02/2006*
    Starting_Date 04/01/2006 the result for Ending_Date = 04/03/2006
    Starting_Date 05/01/2006 the result for Ending_Date = 05/02/2006*
    Starting_Date 06/01/2006 the result for Ending_Date = 06/02/2006*
    Starting_Date 07/01/2006 the result for Ending_Date = 07/03/2006
    Starting_Date 08/01/2006 the result for Ending_Date = 08/02/2006*
    Starting_Date 09/01/2006 the result for Ending_Date = 09/04/2006**
    Starting_Date 10/01/2006 the result for Ending_Date = 10/02/2006
    Starting_Date 11/01/2006 the result for Ending_Date = 11/02/2006*
    Starting_Date 12/01/2006 the result for Ending_Date = 12/04/2006*

    I maybe using this function with the wrong understanding?


    Thanks for any suggestions or input.

  2. #2
    "Certified" Alphaholic Scott Emerick's Avatar
    Real Name
    Scott Emerick
    Join Date
    Dec 2000
    Location
    Central Virginia/ North Carolina Border
    Posts
    2,154

    Default Looks right to me

    What are you expecting to see??

    date = {05/17/2006}
    Month_start = {05/01/2006} which is the first day of the month of Date()
    Add_bus_days({05/01/2006},1) adds 1 bus day which = {05/02/2006}

    This is all correct. If you explain what you need, we can help better.

    Scott

  3. #3
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default

    Quote Originally Posted by Scott Emerick
    What are you expecting to see??

    date = {05/17/2006}
    Month_start = {05/01/2006} which is the first day of the month of Date()
    Add_bus_days({05/01/2006},1) adds 1 bus day which = {05/02/2006}

    This is all correct. If you explain what you need, we can help better.

    Scott
    Also you have to set up the holiday dates in the built-in holiday table or create your own and you have to set the ignore holiday flag to something other than null.

    ? add_bus_days({09/01/2006},1,"N")
    = {09/05/2006}

  4. #4
    Member
    Real Name
    Reed Orbs
    Join Date
    Oct 2005
    Posts
    59

    Default

    Using this function add_bus_day(month_start(date(),1) with system date set to 01/01/2006 the result is 01/02/2006 which is the first business day of the month January 2006.

    Using this function add_bus_day(month_start(date(),1) with system date set to 02/01/2006 the result is 02/02/2006 which is the second business day of the month February 2006.

    The function in both cases should return the ether the 1st or the 2nd business day of thier respective months?

    Thanks for your help?

  5. #5
    Member
    Real Name
    Reed Orbs
    Join Date
    Oct 2005
    Posts
    59

    Default

    What I am attempting to do is to make work day only calendars form using the system date and the month_start function to start the begining date for each of the 20 - 22 fields for the month. But I'am not getting any consistency from the function. The holiday.dbf is setup with hollidays that match the US Post Office.

    I have each field setup on initiate and it fills in the header for each work day of the month. The only difference in each function is the day of the month is the number of days to add.
    add_bus_days(month_start(date()),0) = day1
    add_bus_days(month_start(date()),1) = day2
    add_bus_days(month_start(date()),2) = day3
    and so on....

    I did a small example of what I am getting as results. from the add_bus_days funtion.

    Using this function add_bus_day(month_start(date(),1) with system date set to 01/01/2006 the result is 01/02/2006 which is the first business day of the month January 2006.

    Using this function add_bus_day(month_start(date(),1) with system date set to 02/01/2006 the result is 02/02/2006 which is the second business day of the month February 2006.

    The function in both cases should return the ether the 1st or the 2nd business day of thier respective months?

    I did some more diagnostics and futher found that the function almost works when you start the function with 0 add on days. It does for February 2006 but not for January 2006

    Thanks for your help?

  6. #6
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,311

    Default

    Using this function add_bus_day(month_start(date(),1) with system date set to 01/01/2006 the result is 01/02/2006 which is the first business day of the month January 2006.

    Using this function add_bus_day(month_start(date(),1) with system date set to 02/01/2006 the result is 02/02/2006 which is the second business day of the month February 2006.

    The function in both cases should return the ether the 1st or the 2nd business day of thier respective months?
    I don't accept your premise. These functions don't test whether the first day of the month is itself a business day. All they do in your expressions is begin with the first day of the month, and then add one business day. They seem to be working as intended. Either you need to account for the fact that the first day of the month is or is not a business day, or I guess I need to learn what I'm missing.

    why not start with the last day of the previous month ?

    Alternatively, why not step through all the days of each month discarding those that are not business days ?

    -- tom

  7. #7
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default

    Quote Originally Posted by reedorbs
    What I am attempting to do is to make work day only calendars form using the system date and the month_start function to start the begining date for each of the 20 - 22 fields for the month. But I'am not getting any consistency from the function. The holiday.dbf is setup with hollidays that match the US Post Office.

    I have each field setup on initiate and it fills in the header for each work day of the month. The only difference in each function is the day of the month is the number of days to add.
    add_bus_days(month_start(date()),0) = day1
    add_bus_days(month_start(date()),1) = day2
    add_bus_days(month_start(date()),2) = day3
    and so on....

    I did a small example of what I am getting as results. from the add_bus_days funtion.

    Using this function add_bus_day(month_start(date(),1) with system date set to 01/01/2006 the result is 01/02/2006 which is the first business day of the month January 2006.


    The function in both cases should return the ether the 1st or the 2nd business day of thier respective months?

    I did some more diagnostics and futher found that the function almost works when you start the function with 0 add on days. It does for February 2006 but not for January 2006

    Thanks for your help?
    I responded to your private message separately but for anyone else who is interested, the add_bus_days() function explicitly prohibits the use of zero as the second parameter so I am not surprised by the inconsistency.

    I am struggling with the question at hand.


    Using this function add_bus_day(month_start(date(),1) with system date set to 01/01/2006 the result is 01/02/2006 which is the first business day of the month January 2006.
    January 2, 2006 is a Monday which is the first business day after Jan 1, 2006 - we're right here.

    Using this function add_bus_day(month_start(date(),1) with system date set to 02/01/2006 the result is 02/02/2006 which is the second business day of the month February 2006.
    Feb 2, 2006 is a Thursday, the first business day after Feb 1, 2006 so we're ok here.

    The function in both cases should return the ether the 1st or the 2nd business day of thier respective months?
    - should and does.

    I don't see what the issue is.

  8. #8
    Member
    Real Name
    Reed Orbs
    Join Date
    Oct 2005
    Posts
    59

    Default The first business day of February 2006 is WED not Thursday

    The first business day of February 2006 is WED.

    That's the problem.

    Thanks for your input, any ideas?

  9. #9
    Member
    Real Name
    Reed Orbs
    Join Date
    Oct 2005
    Posts
    59

    Default

    This is what I figured out to create a Monthly Work Day Calendar, and yes Zero does work on the add_bus_days function. I saw the relationship of the function changing with the first day starting on a week-end when I was explaining how the add_bus_days function was inconsistent.

    'Set 'Value' property of 'Day1' .
    DIM form_name as c
    Dim weekday as c
    if is_object(topparent.this) then
    form_name = topparent.name()+".this"
    else
    form_name = ""
    end if

    weekday = cdow(month_start(date()))

    IF is_one_of(weekday,"Saturday"+crlf()+"Sunday"+crlf())THEN
    DELETE expression_result
    expression_result = eval("add_bus_days(month_start(date()),1)",form_name)
    topparent:Day1.value = expression_result
    END IF

    IF is_one_of(weekday,"Monday"+crlf()+"Tuesday"+crlf()+"Wednesday"+crlf()+"Thursday"+crlf()+"Friday"+crlf())THEN
    DELETE expression_result
    expression_result = eval("add_bus_days(month_start(date()),0)",form_name)
    topparent:Day1.value = expression_result
    END IF

  10. #10
    Member
    Real Name
    Reed Orbs
    Join Date
    Oct 2005
    Posts
    59

    Default

    For each field in the Calendar header you copy the code and then increment the previous Saturday Sunday Add_Days by 1 or matching it to the number of the work day in the month as well as incrementing the Monday - Friday Add_days by 1 which will always be 1 less than that of the previous.

  11. #11
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default

    Quote Originally Posted by reedorbs
    For each field in the Calendar header you copy the code and then increment the previous Saturday Sunday Add_Days by 1 or matching it to the number of the work day in the month as well as incrementing the Monday - Friday Add_days by 1 which will always be 1 less than that of the previous.
    I think you solved your issue. Here's a function which returns a crlf() delimited list of business days in the month of any given date, I think.

    Code:
    FUNCTION bus_list AS C (seed AS D )
    dim st as n
    dim nd as n
    dim day_before as d
    dim bus_days as c
    st = day(month_start(seed))
    nd = day(month_end(seed))
    day_before = month_start(seed)-1
    bus_days = ""
    for i = st to nd
    	if month(add_bus_days(day_before,i)) = month(seed)
    	bus_days = bus_days + ","+dtoc(add_bus_days(day_before,i))
    	end if
    next i
    bus_days = stritran(bus_days,",","",1,1)
    bus_list = stritran(bus_days,",",crlf()) 
    END FUNCTION
    Sample output

    Code:
    ? bus_list({01/01/2006})
    = 01/02/2006
    01/03/2006
    01/04/2006
    01/05/2006
    01/06/2006
    01/09/2006
    01/10/2006
    01/11/2006
    01/12/2006
    01/13/2006
    01/16/2006
    01/17/2006
    01/18/2006
    01/19/2006
    01/20/2006
    01/23/2006
    01/24/2006
    01/25/2006
    01/26/2006
    01/27/2006
    01/30/2006
    01/31/2006

  12. #12
    Member
    Real Name
    Reed Orbs
    Join Date
    Oct 2005
    Posts
    59

    Default

    Cool, Thanks,

    I did solve my own results, but still not sure that the function add_bus_days works properly between months.

Similar Threads

  1. add_bus_days(month_start(date()),0,"no") Showing weekend
    By reedorbs in forum Alpha Five Version 7
    Replies: 2
    Last Post: 01-03-2006, 06:08 AM
  2. Date format when typing in the date?
    By Wanda Tucker in forum Web Application Server v6
    Replies: 1
    Last Post: 10-02-2005, 02:08 PM
  3. Start date & Week ending date..
    By rae4sp in forum Alpha Five Version 6
    Replies: 2
    Last Post: 09-22-2005, 11:29 AM
  4. Date Prompt Using 2 Date Fields
    By forskare in forum Alpha Five Version 5
    Replies: 5
    Last Post: 10-08-2002, 03:22 AM
  5. How do you compare a date to a null date?
    By Ilesh Mistry in forum Alpha Five Version 4
    Replies: 5
    Last Post: 10-29-2001, 03:38 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •