Synthetic Classic has reached end of support and is no longer available. Existing Synthetic Classic customers have been upgraded to the all-in-one Dynatrace software intelligence platform.

JavaScript functions for dynamic dates

JavaScript contains many functions to handle dates, without the use of the Gomez Sizzle library. In this example, simple date functions are used in order to set a checkin and checkout date 30 and 32 days out from the current day.

// Get today's date
var now = new Date(); 
// Set Checkin date 30 days from now
var checkin = new Date();

// Set Checkout date 32 days from now
var checkout = new Date();

// Set Checkin Fields
document.getElementById("checkin_day").value = checkin.getDate();
document.getElementById("checkin_year").value = checkin.getFullYear();
document.getElementById("checkin_month").value = checkin.getMonth()+1;

// Set Checkout Fields
document.getElementById("checkout_monthday").value = checkout.getDate();
document.getElementById("checkout_year").value = checkout.getFullYear();
document.getElementById("checkout_month").value = checkout.getMonth()+1;

You'll notice in the example above, there are three separate date fields, one for month, one for day, and one for year. In some cases, you might need to concatenate these together into a single field, depending on what the site's source code actually looks like. Also, since we are working directly with the web page, the code should go in to a Custom action using gomez_top[0] as the target window.

Note that getDate() returns the numeric day of the month and getFullYear() returns the 4 digit year; getMonth(), which returns the numeric value of the month, is zero based, so January is 0, February is 1... December is 11.