2 Replies Latest reply on Feb 2, 2017 12:06 AM by ChristofferRexen_1

    CF Calc Date Help

    ChristofferRexen_1

      Got this Custom Function, which I don't quite understand why is miscalculating.

      https://www.briandunning.com/cf/680

      // CF Name = DV_DateRange365Days

       

      Let(

      [

      availableDates = Case (

      not IsEmpty(startDate) and IsValid(startDate) and not IsEmpty (finishDate) and IsValid(finishDate) ; "both" ;

      not IsEmpty(startDate) and IsValid(startDate) and IsEmpty (finishDate) ; "start" ; "none" ) ;

       

      days = Case (

      availableDates = "both" ; finishDate - startDate ;

      availableDates = "start" ; Get(CurrentDate) - startDate ) ;

       

      months = Round ( days/30 ; 0 ) ;

      years = Round ( days/364,25 ; 0 )

      ];

       

      Case

      (

      returnType = "d" ; days ;

      returnType = "m" ; months ;

      returnType = "y" ; years

      )

      )

      Furthermore I got this CF.

      Self made.

      // CF Name = DV_UdregnPeriodiskPræmieDays365

      // Calculates the periodic premium, based on the number of days the insurance is designed for

      // In:
      // Insurance premium, Days the insurance is signed for
      // OUT:
      // 1st prize, measured in danish kroner distributed
      in A whole year

      // Constants in FEATURE: 365 (days)

       

      //////////

      Let (

      // vars

      [

      days = 365 ;

      result = ( premium / days ) * period

      ] ;

      // calc

      Round ( result ; 2 )

      )

       

      Now, when trying to use the two CFs'

      KUN_Kunde_Police_Policetype::__kp_PolicetypeID = 80121 ; DV_UdregnPeriodiskPræmieDays365 ( ( Premium * KUN_Kunde_Police::Vandmængde ) ; DV_DateRange365Days ( DateStart ; DateEnd ; "d" ) )

       

      DateStart = 01.01.2017

      DateEnd = 31.12.2017

       

      Although when trying this, the DV_DateRange365Days only calculates 364 days, despite the fact there is 365.


      Could anyone lead me in the right direction?


      Regards

      CR

        • 1. Re: CF Calc Date Help
          Magnus Fransson

          Hi Cristoffer,

           

          The reason is that the days calculation does NOT include both start AND end dates as part of the defined period.

          availableDates = "both" ; finishDate - startDate ;

          availableDates = "start" ; Get(CurrentDate) - startDate ) ;

          Just add +1 to adjust that.

          availableDates = "both" ; finishDate - startDate +1 ;

          availableDates = "start" ; Get(CurrentDate) - startDate +1 ) ;

          With best regards Magnus Fransson.

          • 2. Re: CF Calc Date Help
            ChristofferRexen_1

            Magnus Fransson wrote:

             

            Hi Cristoffer,

             

            The reason is that the days calculation does NOT include both start AND end dates as part of the defined period.

            availableDates = "both" ; finishDate - startDate ;

            availableDates = "start" ; Get(CurrentDate) - startDate ) ;

            Just add +1 to adjust that.

            availableDates = "both" ; finishDate - startDate +1 ;

            availableDates = "start" ; Get(CurrentDate) - startDate +1 ) ;

            With best regards Magnus Fransson.

            You are the man!

            TY!