Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Replacing Month number with month name

parria1
8 - Asteroid

I have a data set with the field mth with values 1 through 12. I changed the data type to a string.

I'm trying to replace the mth number with a month name, so 1=Jan, 2=Feb and so on.

I've tried the switch, IIF and If then else formulas on current field and they change the mth field name to Jan. not what i'm after

the formula editor does not recognize my mth field as a variable.

13 REPLIES 13
Parinita
6 - Meteoroid

 Hi parria1, 

 

I have a small doubt in the below formula that why we are using "0" here padleft(tostring([mth]),2,"0") -

 

datetimeformat("2000-"+padleft(tostring([mth]),2,"0")+"-01","%b")

 

DN
8 - Asteroid

datetimeformat requires the standard Alteryx datetime format 'yyyy-mm-dd'. Since the Year and Day are not relevant, we can provide a dummy value (hence 2000- and -01; note the "-" is for formatting to conform the datetime format)

padleft with zero (0) is used as follow: if month is one digit, padleft(tostring([mth]),2,"0") will return 01 02 03 when month=1,2,3 but keep 10 11 12 unchanged because already 2 characters.

ak2018
8 - Asteroid

I know this has been marked as solved, but have you attempted the DateTime tool? I use it to get the Month name  or to format the way you are specifying by using the Custom option. 

sknowlesHS
7 - Meteor

As soon as I read "because I'm lazy" I knew I had to try this. I have a former colleague who used to say that all the time & really, they were just being smart & efficient. After 15 min of troubleshooting this simple formula answered my issue. Now I need to research the datetimeformat page to really understand what it is doing so I can reproduce later. Thanks :)

Labels