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
  • 1.  Calculate Number of working days from a datetime

    Employee
    Posted 01-07-2015 00:00

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

    Originally posted by: dglavastorm

    Hi, I need to find a way to calculate the number of working days from a particular start date to it's closing date, even if that start date is on a weekend

    eg.
    Start date Close Date
    05/01/2015 06/01/2015 = 1 Day
    04/01/2015 06/01/2015 = 1 Day
    03/01/2015 06/01/2015 = 1 Day
    02/01/2015 06/01/2015 = 2 Day

    I found a very old thread from the start of last year but it didn't seem to resolve the query.

    Thanks as always,
    Dave


  • 2.  RE: Calculate Number of working days from a datetime

    Employee
    Posted 01-07-2015 07:01

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

    Originally posted by: ejones

    There is now a "Calculate Workdays" node in the LAL1 library that seems to be doing what you want. But it seems to be counting the starting date where you are not. So taking its result and subtracting one seems to be what you want to do. Cut and paste the nodes below into BRE to see what I just tried.

    node:Calculate_Workdays
    bretype:lal1::Calculate Workdays
    editor:sortkey=54ad38df141a0a51
    input:54ad38df071b711e/=BRD_Data.40fe6c55598828e5
    output:@534676d96a695908/=
    prop:EndDate='Close Date'
    prop:EndDateParamType=Field
    prop:StartDate='Start Date'
    prop:StartDateParamType=Field
    editor:XY=190,60
    end:Calculate_Workdays

    node:BRD_Data
    bretype:core::Static Data
    editor:Label=Start Date, Close Date
    editor:sortkey=54ad3589056c6e1e
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    Start Date:date,Close Date:date
    2015-01-05,2015-01-06
    2015-01-04,2015-01-06
    2015-01-03,2015-01-06
    2015-01-02,2015-01-06
    EOX
    editor:XY=110,60
    end:BRD_Data


  • 3.  RE: Calculate Number of working days from a datetime

    Employee
    Posted 01-07-2015 23:34

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

    Originally posted by: dglavastorm

    Hi, I tried to paste but this just comes up with a white square that can't do anything ..

    node:Calculate_Workdays
    bretype:lal1::Calculate Workdays
    editor:sortkey=54ad38df141a0a51
    input:54ad38df071b711e/=BRD_Data.40fe6c55598828e5
    output:@534676d96a695908/=
    prop:EndDate='Close Date'
    prop:EndDateParamType=Field
    prop:StartDate='Start Date'
    prop:StartDateParamType=Field
    editor:XY=190,60
    end:Calculate_Workdays

    I've also got the Lal1 in my base libraries but can't find the node.


  • 4.  RE: Calculate Number of working days from a datetime

    Employee
    Posted 01-08-2015 07:51

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

    Originally posted by: ejones

    What version of LAE are you using?

    Because, I just checked the page where we can download LAL1 and it shows that the "Calculate Workdays" node is not available in 4.6. Just to make sure I downloaded and installed the LAL1 library for 4.6 and it is not even listed.

    So if you are using 4.x it seems that it will be much harder. But you could use the BRAINscript date functions to figure out what days of the week are involved and calculate it.


  • 5.  RE: Calculate Number of working days from a datetime

    Employee
    Posted 01-09-2015 07:12

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

    Originally posted by: khopkins

    Hi all,

    You could always try the solution i had from this forum post for a purely brainscript version
    http://community.lavastorm.com/threa...light=workdays

    Keith


  • 6.  RE: Calculate Number of working days from a datetime

    Employee
    Posted 01-13-2015 02:13

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

    Originally posted by: andycooper

    I have created a simple example using the BRAINScript link above: -

    node:Start_Date_Close_Date
    bretype:core::Static Data
    editor:Label=Start Date, Close Date
    editor:sortkey=54ad3589056c6e1e_2
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    Start Date:date,Close Date:date
    2015-01-05,2015-01-06
    2015-01-04,2015-01-06
    2015-01-03,2015-01-06
    2015-01-02,2015-01-06
    EOX
    editor:XY=390,100
    end:Start_Date_Close_Date

    node:Calculate_Workdays__BRAINScript
    bretype:core::Filter
    editor:Label=Calculate Workdays - BRAINScript
    editor:sortkey=54b4de8b50cf3082
    input:@40fd2c74167f1ca2/=Start_Date_Close_Date.40fe6c55598828e5
    output:@40fd2c7420761db6/=
    prop:Script=<<EOX
    weekDays = 1 + (dateSubtract('Close Date','Start Date') * 5 - ('Start Date'.weekday()-'Close Date'.weekday()) * 2) / 7;
    if ('Close Date'.weekday() == 6) then weekDays = weekDays -1
    if ('Start Date'.weekday() == 0) then weekDays = weekDays -1


    emit 'Start Date'
    emit 'Close Date'
    emit weekDays.int() as "weekDays"

    EOX
    editor:XY=470,100
    end:Calculate_Workdays__BRAINScript

    If you wanted to exclude the start date itself then you could simply change the emit line to emit weekDays.int() -1 as "weekDays"

    Thanks

    Andy


  • 7.  RE: Calculate Number of working days from a datetime

    Employee
    Posted 01-19-2015 21:43

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

    Originally posted by: dglavastorm

    Thanks Andy, worked like a charm.

    Cheers,

    Dave