Skip to content

getDayNameShort β€” GTM Variable Template for Date

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

Returns the abbreviated name of the day of the week. 1 = Mon, 7 = Sun (ISO 8601).


Date Formatting

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


Index 1 returns Mon
INPUT
Day Index: 1
OUTPUT
Mon
Invalid index returns undefined
INPUT
Day Index: 10
OUTPUT
undefined

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

getDayNameShort
Day Index
πŸ’Ύ An ISO 8601 day number (1 = Monday, 7 = Sunday).

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.
Day Index number
πŸ’‘ Type any text to see the result update live
🎯 Using special value β€” click input to type instead
Test with:
Falsy
Truthy
getDayName()


πŸ“œ View Implementation Code
/**
* Returns the abbreviated name of the day of the week based on the given integer where 0 = Monday, 1 = Tuesday, etc.
*
* @param {number|string} data.src - An integer representing the day of the week (0 to 6).
* @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 day (e.g., "Mon", "Tues", etc.), or undefined if the index is invalid.
*
* @framework ggLowCodeGTMKit
*/
const makeNumber = require('makeNumber');
const getDayName = function(dayInt) {
const day = makeNumber(dayInt);
if (day < 1 || day > 7) return undefined;
const dayList = ["Mon", "Tues", "Wed", "Thu", "Fri", "Sat", "Sun"];
return dayList[day - 1];
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// getDayName - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(getDayName(value));
// ===============================================================================
// getDayName() – Apply Mode: runtime parameter
// ===============================================================================
/*
return function(value) {
return out(getDayName(value));
};
*/
πŸ§ͺ View Test Scenarios (4 tests)
βœ… '[example] Index 1 returns Mon'
βœ… Valid day index 4 - returns Thursday
βœ… Valid day index 7 - returns Sunday
βœ… '[example] Invalid index returns undefined'