reverseDateCompactYear1st — GTM Variable Template for Date
reverseDateCompactYear1st EXTENDED Date
Reverse a compact date string from "yyyymmdd" to "ddmmyyyy" format with no separators.
Examples
Reverse yyyymmdd to ddmmyyyy
INPUT
Compact Date String: 20241225
OUTPUT
25122024
Leading zeros handled
INPUT
Compact Date String: 20250101
OUTPUT
01012025
GTM Configuration
This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
reverseDateCompactYear1st
Compact Date String
💾 The compact date string with no separators, starting with year (yyyymmdd format).
Supported formats:
✓ String
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.
Compact Date String number
💡 Type any text to see the result update live
🎯 Using special value — click input to type instead
Test with:
Falsy
Truthy
🔗 Result Handling — Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
reverseDateCompactYear1st()
Related Variables
Same category: Date
Under the Hood
📜 View Implementation Code
/**
* Reverse a compact date string from "yyyymmdd" to "ddmmyyyy".
*
* @param {string} data.src - The compact date string with no separators, starting with year.
* @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 reversing.
*
* @returns {string|undefined} The reversed date string, or undefined if the input is invalid.
*
* @framework ggLowCodeGTMKit
*/
const reverseDateCompactYear1st = function(date) {
if (typeof date !== 'string' || date.length !== 8) { return undefined; }
const year = date.substring(0, 4);
const month = date.substring(4, 6);
const day = date.substring(6, 8);
return day + month + year;
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// reverseDateCompactYear1st - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(reverseDateCompactYear1st(value));
// ===============================================================================
// reverseDateCompactYear1st() – Apply Mode
// ===============================================================================
/*
return function(value) {
return out(reverseDateCompactYear1st(value));
};
*/🧪 View Test Scenarios (3 tests)
✅ '[example] Reverse yyyymmdd to ddmmyyyy'
✅ '[example] Leading zeros handled'
✅ Valid date end of year - reverses correctly