Skip to content

extendedDateToBasic — GTM Variable Template for Time

VARIABLES › TIME
extendedDateToBasic EXTENDED Time

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


Examples

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

GTM Configuration

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()


Under the Hood

📜 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