Timestamp Formatting For Hidden Field On Form


Hello Everyone,

I had a quick question I know you Javascript junkies will know. I just can’t seem to figure this out.

Below I have some JavaScript, that is working and populating the field. But this is what it is passing “Wed Dec 22 2021 13:44:05 GMT-0500 (Eastern Standard Time)”. This needs to be formatted as such, with a space in between: MM/DD/YYYY HH:MM:SS (for Google Ad tracking).

Any help would be great. Below is the Javascript I am using, but it is not formatted properly. Thanks.

// Change the word Date_Submitted in the following line to the name of your hidden field label.
// It has to match exact label, including capitals, underscore, etc...
var inpElm = document.getElementById('Conversion_Time');                                    
var d = new Date();
var pD = d;
window.setTimeout(sD, 5000);
window.setInterval(sD, 30000);
function sD(){
inpElm.value = d;

There are a lot of method for Date object:

When there’s no one fits what you need, you can extract each values you want with Date.prototype.get…, store each of them in a variable and serve them with string interpolation [single backtick]${MMvariable} / ${DDvariable} …[single backtick]

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.