reverseDateSlash β GTM Variable Template for Date
reverseDateSlash EXTENDED Date
Reverses a date string between "dd/mm/yyyy" and "yyyy/mm/dd" formats.
When to Use This
Section titled βWhen to Use ThisβExamples
Section titled βExamplesβReverse dd/mm/yyyy
INPUT
Date String: 25/12/2024
OUTPUT
2024/12/25
Reverse yyyy/mm/dd
INPUT
Date String: 2025/01/01
OUTPUT
01/01/2025
Live Sandbox
Section titled βLive SandboxβThis is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
reverseDateSlash
Date String
πΎ The date string to reverse, using slash separators.
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.
Date String string
π‘ 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.
reverseDateSlash()
Related Variables
Section titled βRelated VariablesβSame category: Date
Under the Hood
Section titled βUnder the Hoodβπ View Implementation Code
/*** Reverse a date string between "dd/mm/yyyy" and "yyyy/mm/dd" formats.** @param {string} data.src - The date string to reverse, using slash separators.* @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 reverseDateSlash = function(date) { if (typeof date === 'string') { const parts = date.split('/'); if (parts.length === 3) { return parts.reverse().join('/'); } } return undefined;};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;const out = safeFunction(data.out);
// ===============================================================================// reverseDateSlash - Direct mode// ===============================================================================const applyCast = (castFn, value) => safeFunction(castFn)(value);const value = applyCast(data.pre, data.src);return out(reverseDateSlash(value));// ===============================================================================// reverseDateSlash() β Apply Mode// ===============================================================================/*return function(value) { return out(reverseDateSlash(value));};*/π§ͺ View Test Scenarios (5 tests)
β
'[example] Reverse dd/mm/yyyy'β
'[example] Reverse yyyy/mm/dd'β
Valid date with leading zeros - reverses correctlyβ
Invalid format without slashes - returns undefinedβ
Invalid format with wrong number of parts - returns undefined