Skip to main content
vempatir680997
Inspiring
Jan 4, 2023 12:09 PM UTC
Question

how to extract month and year from 4 digit numbers

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

7 replies

konduruc733182
Inspiring
Jan 4, 2023 12:30 PM UTC

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
Inspiring
Jan 8, 2023 5:26 AM UTC

thanks for the answer

harshitb6843
Brainy
Jan 4, 2023 12:33 PM UTC

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
Jan 4, 2023 12:35 PM UTC

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
Inspiring
Jan 4, 2023 12:39 PM UTC

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
Jan 4, 2023 12:43 PM UTC

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
),