Skip to content

millisecondsToDays β€” GTM Variable Template for Date

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

Converts milliseconds to days.


Time Operations

Measure durations, calculate elapsed time, and format timestamps.

Type Conversion

Safely convert between data types β€” strings, numbers, booleans, arrays, objects.

Date & Time

Calculate durations, differences, and time-based operations on date values.


Milliseconds to 1 day
INPUT
Number of Milliseconds: 86400000
OUTPUT
1
Milliseconds to 7 days
INPUT
Number of Milliseconds: 604800000
OUTPUT
7

This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.

millisecondsToDays
Number of Milliseconds
πŸ’Ύ The number of milliseconds to convert to days.

Supported formats:
  βœ“ Number
  βœ“ 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.
Number of Milliseconds number
πŸ’‘ Type any text to see the result update live
🎯 Using special value β€” click input to type instead
Test with:
Falsy
Truthy
millisecondsToDays()


πŸ“œ View Implementation Code
/**
* Converts a number of milliseconds to days.
*
* @param {string|number} data.src - The number of milliseconds to convert to days.
* @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 {number|undefined} The time in days, or undefined if input is not a valid number.
*
* @framework ggLowCodeGTMKit
*/
const makeNumber = require('makeNumber');
const millisecondsToDays = function(timeValue) {
const timeNum = makeNumber(timeValue);
if (timeNum === timeNum) {
return timeNum / (1000 * 60 * 60 * 24);
}
return undefined;
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// millisecondsToDays - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(millisecondsToDays(value));
// ===============================================================================
// millisecondsToDays() – Apply Mode
// ===============================================================================
/*
return function(value) {
return out(millisecondsToDays(value));
};
*/
πŸ§ͺ View Test Scenarios (5 tests)
βœ… '[example] Milliseconds to 1 day'
βœ… '[example] Milliseconds to 7 days'
βœ… String milliseconds - converts to days
βœ… Partial day milliseconds - converts to decimal days
βœ… Invalid string input - returns undefined