Skip to content

Instantly share code, notes, and snippets.

@asmattic
Created June 21, 2019 03:23
Show Gist options
  • Save asmattic/4a46d02e51ddef0886ce50f20c759942 to your computer and use it in GitHub Desktop.
Save asmattic/4a46d02e51ddef0886ce50f20c759942 to your computer and use it in GitHub Desktop.
Format JavaScript date to common western string format (e.g. September 10, 2019)
// Date formatter function
function formatDateString(dateExecutionVar) {
var date = new Date(execution.getVariable(dateExecutionVar));
var monthList = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var month = monthList[date.getMonth()];
var day = date.getDate().toString();
var year = date.getFullYear().toString();
return month + ' ' + day + ', ' + year;
}
execution.setVariable('Formatted_Date', formatDateString('Date'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment