Skip to content

extendedDateToBasic β€” GTM Variable Template for Date

VARIABLES β€Ί DATE
extendedDateToBasic EXTENDED Date
Direct (.tpl) Apply (.tpl)

Converts an extended ISO date (YYYY-MM-DD) to basic format (YYYYMMDD).


Date Formatting

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

Type Conversion

Safely convert between data types β€” strings, numbers, booleans, arrays, objects.

Date & Time

Calculate durations, differences, and time-based operations on date values.


Extended to basic ISO date
INPUT
Extended Date: 2024-12-25
OUTPUT
20241225
Invalid returns undefined
INPUT
Extended Date: 2024-12-2
OUTPUT
undefined

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

extendedDateToBasic
Extended Date
πŸ’Ύ The extended date string in "yyyy-mm-dd" format.

Supported formats:
  βœ“ 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.
Extended Date string
πŸ’‘ Type any text to see the result update live
🎯 Using special value β€” click input to type instead
Test with:
Falsy
Truthy
extendedDateToBasic()


πŸ“œ View Implementation Code
/**
* Convert an extended ISO 8601 date string (yyyy-mm-dd) to basic ISO format (yyyymmdd).
*
* @param {string} data.src - The extended date string in "yyyy-mm-dd" format.
* @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 date in "yyyymmdd" format, or undefined if the input is invalid.
*
* @framework ggLowCodeGTMKit
*/
const extendedDateToBasic = function(date) {
if (typeof date !== 'string' || date.length !== 10) { return undefined; }
return date.split('-').join('');
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// extendedDateToBasic - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(extendedDateToBasic(value));
// ===============================================================================
// extendedDateToBasic() – Apply Mode
// ===============================================================================
/*
return function(value) {
return out(extendedDateToBasic(value));
};
*/
πŸ§ͺ View Test Scenarios (5 tests)
βœ… '[example] Extended to basic ISO date'
βœ… Valid date with January first - converts correctly
βœ… Valid date end of year - converts correctly
βœ… '[example] Invalid returns undefined'
βœ… Non-string input - returns undefined