Skip to main content
vempatir680997
January 4, 2023
Question

how to extract month and year from 4 digit numbers

  • January 4, 2023
  • 7 replies
  • 0 views

for example my input is 0323 and i need output march-2023 (or) 03-2023

7 replies

konduruc733182
January 4, 2023

Hello ramganeshv6858,

Try this code and change it according to your requirement. this might do the work. you can also wait for replies with some easy steps from experts.

a!localVariables(
  local!value:"0323",
local!split:a!forEach(
  items: enumerate(len(local!value))+1,
  expression: local!value[fv!item]
  ),
  local!month:tointeger(concat(local!split[1],local!split[2])),
  local!year:tointeger(concat("20",local!split[3],local!split[4])),
  {
  text(date(local!year,local!month,1),"mmm-yyyy")
  }
  )

vempatir680997
January 8, 2023

thanks for the answer

harshitb6843
January 4, 2023

a!localVariables(
  local!input: "0323",
  local!month: tointeger(index(local!input, { 1, 2 }, {})),
  local!year: tointeger(
    concat("20", index(local!input, { 3, 4 }, {}))
  ),
  text(
    date(local!year, local!month, 1),
    "m-yyyy"
  )
)

You can change the value of "m" to "mmm" to print the 3 letters of the month's name

Participating Frequently
January 4, 2023

Hello [mention:ec5065f0ca8845eeb4dc43351566d691:e9ed411860ed4f2ba0265705b8793d05],

You can try this too, Hope it helps

local!date:"0323",
local!newDate:concat(left(local!date,2),"-20",right(local!date,2)),

konduruc733182
January 4, 2023

Hello anshikag0001,

'0323' is the resultant output. for the code you have given. May be you haven't copied the complete code here.

Participating Frequently
January 4, 2023

Pls check the output for local!newDate variable.

a!localVariables(
  local!date: "0323",
  local!newDate: concat(
    left(local!date, 2),
    "-20",
    right(local!date, 2)
  ),
  local!newDate
),