Hi All, Currently I am working on a requirement where we need to comp

Certified Senior Developer
Hi All,

Currently I am working on a requirement where we need to compute the number of months based on start date and end date. Suppose say for example start date is 25/12/2015 and end date is 31/03/2017. The total number of months should be calculated as 15 months including the date precision. How to achieve this functionality?

OriginalPostID-183629

OriginalPostID-183629

  Discussion posts and replies are publicly visible

Parents
  • The above code, which i was shared, fails in some scenarios, Check with the below code. I feel it will fulfill your requirement
    with(
    local!years:year(ri!todate)-year(ri!fromDate),
    local!months:(local!years)*12+(month(ri!todate)-month(ri!fromdate))-1,
    local!days:(daysinmonth(month(ri!fromdate),year(ri!fromDate))-day(ri!fromDate))+day(ri!todate),
    if(
    local!days>=fn!daysinmonth(month(ri!todate),year(ri!toDate)),
    local!months+1&" months, "&local!days-fn!daysinmonth(month(ri!todate),year(ri!toDate))&" days",
    local!months&" months, "&local!days&" days"
    )
    )
Reply
  • The above code, which i was shared, fails in some scenarios, Check with the below code. I feel it will fulfill your requirement
    with(
    local!years:year(ri!todate)-year(ri!fromDate),
    local!months:(local!years)*12+(month(ri!todate)-month(ri!fromdate))-1,
    local!days:(daysinmonth(month(ri!fromdate),year(ri!fromDate))-day(ri!fromDate))+day(ri!todate),
    if(
    local!days>=fn!daysinmonth(month(ri!todate),year(ri!toDate)),
    local!months+1&" months, "&local!days-fn!daysinmonth(month(ri!todate),year(ri!toDate))&" days",
    local!months&" months, "&local!days&" days"
    )
    )
Children
No Data