LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only

Working days

  • 1.  Working days

    Employee
    Posted 01-31-2013 04:39

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: khopkins

    Hi everyone,

    Does anyone know of a way i can calculate the set number of working days between two dates?

    I have been using the dateSubtract function previously but this only give the exact number of days and i need to count the days ignoring weekends.

    Regards,

    Keith


  • 2.  RE: Working days

    Employee
    Posted 01-31-2013 08:42

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    This is a brute-force method: It works, but I wouldn't use it for a large number of input records.

    e=StartDate
    days=0
    while e<EndDate {
    if e.weekday()>0 and e.weekday()<6 then days=days+1
    e=e.dateAdjust(1)
    }
    emit *,days


  • 3.  RE: Working days

    Employee
    Posted 02-06-2013 08:54

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: khopkins

    Thanks Stony that's perfect as i am only running it over a maximum of 1000 records or so.

    However is there a more elegant solution that would be more efficient on large numbers of records?

    Regards,
    Keith


  • 4.  RE: Working days

    Employee
    Posted 02-06-2013 09:19

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hey,

    I haven't really tested this thoroughly, but I just modified an algorithm I found online (http://alecpojidaev.wordpress.com/20...lation-with-c/) to make it work using BRAINscript.
    I ran a couple of tests and it seems to do the right thing for those simple tests but I can't guarantee that it's not missing a corner case somewhere.

    weekDays = 1 + (dateSubtract(end, start) * 5 - (start.weekday()-end.weekday()) * 2) / 7;
    if (end.weekday() == 6) then weekDays = weekDays -1
    if (start.weekday() == 0) then weekDays = weekDays -1
    
    
    emit start
    emit end
    emit weekDays.int() as "weekDays"
    Note: The fields "start" and "end" are expected to be of type "date".

    Tim.


  • 5.  RE: Working days

    Employee
    Posted 02-06-2013 09:22

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: khopkins

    Cheers Tim,

    I will try this one as well many thanks


  • 6.  RE: Working days

    Employee
    Posted 02-06-2013 09:23

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    I need to work out all the details, but here is a (partial) suggestion:

    days=dateSubtract(EndDate,StartDate)
    weeks = int(days/7)
    weekdays = days - weeks*2

    The trouble is you have to then add several IF conditions to adjust for cases when the period starts or ends on a Saturday or Sunday.


  • 7.  RE: Working days

    Employee
    Posted 03-28-2014 05:27

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: gillian33

    Hi I'm very new to lavastorm. I am trying to follow the messages aboove to work out the working days between 2 dates but I am struggling a bit

    I have managed the following to work out the number of days how do I amend this to exclude weekends & bank holidays if possible??

    OrderRecdtoCCTHandedOver = dateSubtract('Install_Date','Create_Date')


  • 8.  RE: Working days

    Employee
    Posted 03-28-2014 05:33

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hey,

    I previously created a node which could do that where it looks up a web service, and provided with the country & region it will calculate the holidays/non holidays/weekdays/workdays etc between a given date range.

    See the post here: http://community.lavastorm.com/threa...-own-functions

    Without querying a web service, you would need to maintain a list of all of the different holidays for all possible regions, across all years of interest, so it seemed better to go with the web service approach.

    Regards,
    Tim.


  • 9.  RE: Working days

    Employee
    Posted 03-28-2014 06:27

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: gillian33

    Thanks for your help I cant open the graph though I think its because I have version 4?


  • 10.  RE: Working days

    Employee
    Posted 03-28-2014 06:37

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hi,

    What version of the LAE are you using?
    This node requires a LAL install with the HTTP node and potentially other LAL nodes (can't recall) as well, so it might not work if you don't have at least LAE 4.6.0+...
    If it's just the HTTP node that it requires (which looks like it should work on LAE 4.5.1) then I can try & put together a version for LAE 4.5.x.


    Tim.


  • 11.  RE: Working days

    Employee
    Posted 03-28-2014 07:33

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: gillian33

    Hi

    Its version 4.5.3.0.

    Thanks


  • 12.  RE: Working days

    Employee
    Posted 03-28-2014 07:49

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hi,

    Ok, I'll take a look and see if I can put together a version that will work on 4.5.3.
    Probably won't be able to get to that today though sorry.

    Tim.


  • 13.  RE: Working days

    Employee
    Posted 03-28-2014 08:02

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: gillian33

    Appreciate your help. Thankyou


  • 14.  RE: Working days

    Employee
    Posted 03-31-2014 11:12

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hi,

    It looks like the HTTP & URL Query Builder nodes which are required by the graph I referenced aren't available in 4.5.x and are only available in LAL releases compatible with LAE 4.6+.

    So I guess I won't be able to backport that to 4.5.3 for you sorry.

    Tim.