Skip to content

secondsToMilliseconds β€” GTM Variable Template for Date

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

Converts seconds to milliseconds.


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.


Seconds to milliseconds
INPUT
Number of Seconds: 5
OUTPUT
5000
Zero returns 0
INPUT
Number of Seconds: 0
OUTPUT
0

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

secondsToMilliseconds
Number of Seconds
πŸ’Ύ The number of seconds to convert to milliseconds.

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 Seconds number
πŸ’‘ Type any text to see the result update live
🎯 Using special value β€” click input to type instead
Test with:
Falsy
Truthy
secondsToMilliseconds()


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