Skip to main content
April 27, 2022
Question

Date

  • April 27, 2022
  • 10 replies
  • 0 views

How I can I convert number of months into year?

    10 replies

    andrewh0007
    April 27, 2022

    Divide by 12?

    You need to give us more to go on. For this it would be good to have expected inputs and outputs. Is this what you're after?

    Input 12 --> Output 1

    Input 36 --> Output 3

    Input 18 --> Output 1.5

    Input 25 --> Output 2.08

    vikashk739
    April 27, 2022

    a!localVariables(
      local!months,
      local!year,
      {
        a!textField(
          label: "Enter month",
          value: local!months,
          saveInto: local!months
        ),
        a!textField(
          label: "Year (s)",
          value: if(
            or(isnull(local!months)),
            "",
            quotient(local!months,12) & " year and " & mod(local!months,12) & " month",
          ),
          saveInto: local!year
        )
      }
    )

    Please try this code

    April 27, 2022

    this is fine ,but now I have the sp rule in which it is returning no of months fox ex: 6 months. i need to use this 6 or 12 or 24 months with the date  and convert into months , how will i do that?

    stewart.burchell
    April 27, 2022

    Do you mean how do I convert, for example 18 months into 1.5 years? or 9 months into 0.75 years? If so, that's a pretty straightforward calculation - divide your number by 12 and, perhaps, express the value to 2 decimals points.

    If that's not what you meant perhaps you can elaborate on your requirement?

    April 27, 2022

    yes I have the sp rule in which it is returning me no of months in terms of days(for ex: 6 months or 12 months in 6 or 12),I need to convert that days (6 days into months) with the date, how i can do this? I need do use sp output only. 

    stewart.burchell
    April 27, 2022

    Now you're introducing "days" into the discussion and you have lost me...I don't understand what you're trying to achieve. Can you provide more detail please.