reverseDateCompactDay1st — GTM Variable Template for Date
reverseDateCompactDay1st EXTENDED Date
Reverses a compact date string from "ddmmyyyy" to "yyyymmdd" format.
Examples
Reverse ddmmyyyy to yyyymmdd
INPUT
Compact Date String: 25122024
OUTPUT
20241225
Invalid length returns undefined
INPUT
Compact Date String: 2512202
OUTPUT
undefined
GTM Configuration
This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
reverseDateCompactDay1st
Compact Date String
💾 The compact date string with no separators, starting with day (ddmmyyyy 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.
reverseDateCompactDay1st()
Related Variables
Same category: Date
Under the Hood
📜 View Implementation Code
/**
* Reverse a compact date string from "ddmmyyyy" to "yyyymmdd".
*
* @param {string} data.src - The compact date string with no separators, starting with day.
* @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 reverseDateCompactDay1st = function(date) {
if (typeof date !== 'string' || date.length !== 8) { return undefined; }
const day = date.substring(0, 2);
const month = date.substring(2, 4);
const year = date.substring(4, 8);
return year + month + day;
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// reverseDateCompactDay1st - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(reverseDateCompactDay1st(value));
// ===============================================================================
// reverseDateCompactDay1st() – Apply Mode
// ===============================================================================
/*
return function(value) {
return out(reverseDateCompactDay1st(value));
};
*/🧪 View Test Scenarios (5 tests)
✅ '[example] Reverse ddmmyyyy to yyyymmdd'
✅ Valid date with leading zeros - reverses correctly
✅ Valid date end of year - reverses correctly
✅ '[example] Invalid length returns undefined'
✅ Non-string input - returns undefined