Skip to content

reverseDateSlash β€” GTM Variable Template for Date

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

Reverses a date string between "dd/mm/yyyy" and "yyyy/mm/dd" formats.



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

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


πŸ“œ 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