Skip to content

Instantly share code, notes, and snippets.

@willjobs
Created October 11, 2017 05:24
Show Gist options
  • Save willjobs/d2c4a92414af23193cbdbfedb48a4263 to your computer and use it in GitHub Desktop.
Save willjobs/d2c4a92414af23193cbdbfedb48a4263 to your computer and use it in GitHub Desktop.
Google Sheets custom function to get month name (either full or 3-character abbreviation), given an integer
function getMonthText(val, short) {
if(val !== parseInt(val,10)) {
return "";
}
if(val < 1 || val > 12) {
return "";
}
var x = "";
switch(val) {
case 1:
x= "January";
break;
case 2:
x= "February";
break;
case 3:
x= "March";
break;
case 4:
x= "April";
break;
case 5:
x= "May";
break;
case 6:
x= "June";
break;
case 7:
x= "July";
break;
case 8:
x= "August";
break;
case 9:
x= "September";
break;
case 10:
x= "October";
break;
case 11:
x= "November";
break;
case 12:
x= "December";
break;
}
if(short) {
x= x.slice(0,3);
}
return x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment