Skip to main content
kavyam0002
Brainy
Jun 21, 2022 10:06 AM UTC
Solved

count no of days

hi,

for ex, if i enter some date from that date till today how many days? how to count no of days 

    stefanhelzle0001
    Brainy
    Jun 21, 2022 10:11 AM UTC

    When you have two dates, you can just subtract them. Wrap it into a tointeger() and you are good to go.

    5 replies

    stefanhelzle0001
    Brainy
    Jun 21, 2022 10:11 AM UTC

    When you have two dates, you can just subtract them. Wrap it into a tointeger() and you are good to go.

    agamb0001
    Participating Frequently
    Jun 21, 2022 10:29 AM UTC

    [mention:bd2e537916fe4b31980bfba549754efc:e9ed411860ed4f2ba0265705b8793d05]

    You could use something like below:

    tointeger(today() - ri!date)

    kavyam0002
    Brainy
    Jun 22, 2022 5:12 AM UTC

    what if i give date along with time how to calculate that [date and time]

    New Participant
    Jun 22, 2022 5:51 AM UTC

    [mention:bd2e537916fe4b31980bfba549754efc:e9ed411860ed4f2ba0265705b8793d05]

    Answer to above query, hope this helps

    mikes0011
    Brainy
    Jun 21, 2022 3:04 PM UTC

    I find it helpful to create an Expression Rule in my environments that can do a null-safe "elapsed days" comparison between any 2 dates, in the manner required by your system (i.e. sometimes if the starting and ending date are the same, you'd want to return a value of "1" instead of "0", in other words doing an "end dates inclusive" value).  For example the following:

    /* RULE_CalculateElapsedDays */
    /* Takes a Start and End date and calculates total elapsed (i.e. deployed) days,
      inclusively -- e.g. if the start and end date are the same day,
      the total elapsed days will be 1 instead of 0. */
    
    if(
      or(
        a!isNullOrEmpty(ri!startDate),
        a!isNullOrEmpty(ri!endDate)
      ),
      tointeger(null()),
      
      tointeger(ri!endDate - ri!startDate) + 1
    )

    The Expression Guru