Skip to main content
kavyam0002
June 21, 2022
Solved

count no of days

  • June 21, 2022
  • 5 replies
  • 0 views

hi,

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

    Best answer by stefanhelzle0001

    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
    June 21, 2022

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

    agamb0001
    June 21, 2022

    [mention:bd2e537916fe4b31980bfba549754efc:e9ed411860ed4f2ba0265705b8793d05]

    You could use something like below:

    tointeger(today() - ri!date)

    kavyam0002
    June 22, 2022

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

    June 22, 2022

    [mention:bd2e537916fe4b31980bfba549754efc:e9ed411860ed4f2ba0265705b8793d05]

    Answer to above query, hope this helps

    mikes0011
    Brainy
    June 21, 2022

    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
    )