Skip to content

getMonthNameShort β€” GTM Variable Template for Date

VARIABLES β€Ί DATE
getMonthNameShort CORE Date
Direct (.tpl) Apply (.tpl)

Returns the abbreviated name of the month. 0 = Jan, 11 = Dec.


Date Formatting

Format and transform date values into human-readable or machine-readable strings.


Index 0 returns Jan
INPUT
Month Index: 0
OUTPUT
Jan
Index 11 returns Dec
INPUT
Month Index: 11
OUTPUT
Dec

This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.

getMonthNameShort
Month Index
πŸ’Ύ An integer representing the month of the year (0 = January, 1 = February, etc.).

Supported formats:
  βœ“ Number
  βœ“ String
Input Setup
Input Function (optional)
βš™οΈ Optional pre-processing function applied to the input before internal logic (e.g., convert object to string, normalize case). Internal transformations such as case handling will still apply afterward.
Result Handling
Output Function (optional)
βš™οΈ Optional function to apply to the result before returning it (e.g., str => str + ' €', val => val !== undefined for boolean conversion). Useful for chaining transformations on the output.
Month Index number
πŸ’‘ Type any text to see the result update live
🎯 Using special value β€” click input to type instead
Test with:
Falsy
Truthy
getMonthNameShort()


πŸ“œ View Implementation Code
/**
* Returns the abbreviated name of the month based on the given integer where 0 = January, 1 = February, etc.
*
* @param {number|string} data.src - An integer representing the month of the year (0 to 11).
* @param {Function|string} [data.out] - Optional output handler: function to transform result or string with format.
*
* Direct-mode specific parameters:
* @param {Function} [data.pre] - Optional pre-processor function to transform src before conversion.
*
* @returns {string|undefined} The abbreviated name of the month (e.g., "Jan", "Feb", etc.), or undefined if the index is invalid.
*
* @framework ggLowCodeGTMKit
*/
const makeNumber = require('makeNumber');
const getMonthNameShort = function(monthInt) {
const month = makeNumber(monthInt);
const monthList = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"];
return monthList[month];
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// getMonthNameShort - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(getMonthNameShort(value));
// ===============================================================================
// getMonthNameShort() – Apply Mode
// ===============================================================================
/*
return function(value) {
return out(getMonthNameShort(value));
};
*/
πŸ§ͺ View Test Scenarios (4 tests)
βœ… '[example] Index 0 returns Jan'
βœ… Valid month index 5 - returns June
βœ… '[example] Index 11 returns Dec'
βœ… Invalid month index - returns undefined