Working with dates

Working with dates/times can occasionally be confusing, depending on what you want to achieve, there a few different methods we'd recommend to use, that we've found work best. 
Scenario 1 - You have a script that needs an outbound call made to a head office during working hours, but require an engineer to be called out of hours. 
var d = new Date();
var n = d.getHours(); 
var s = d.getDay();
if (s == 6 || s == 0 || n >= 17 || n < 9)
We set a few variables (d, n & s) to their relevant date functions, and utilize the Day function to determine if the day is Saturday or Sunday s == 6(Saturday) or s == 0(Sunday), or the hour is >= 17 or < 9. As we've used an or operator '||', not an and operator '&&', if any of these functions are true, the field '[OH]' will be suppressed, and the field '[OOH]' will remain visible. There's not limit to the amount of fields that can be suppressed or shown, so entire fields like table controls containing engineer details can be hidden or shown when needed.
Scenario 2 - A date needs to be entered in script, and you need to ensure agents are NOT selecting a date in the past. 
The below Syntax requires a basic script to see it's functionality, with a date field and two text labels, one named [past] and another named [future].
var date = Date.parse([Date Field]);               //Inserts the string and returns as MS. Ensure ISO standard of date format is used (yyyy-mm-dd)
var d = new Date();
var cuDate = d.getTime();          //Gets the current date in MS
suppressFields('[past]', '[future]');
if(date <= cuDate){
        ('[past]');                  //insert any functionality of choosing
else if(date > cuDate){
        ('[future]');               //insert any functionality of choosing
    Ensure you set the date format to yyyy-mm-dd(ISO standard), to make sure the correct function is seen.
The first part of the code block gets the date field as an ISO format date string, and converts it into the amount of milliseconds from  midnight of Jan 01 1979.
By using milliseconds, we remove the need to compare days in months, which can become confusing. 
The next two lines get the current date in milliseconds from midnight Jan 01 1979, for comparison.
In this example, the two text labels are suppressed, and depending on whether or not date (amount of milliseconds between the selected date and 01/01/1979) is smaller than, or equal to cuDate (amount of milliseconds between the current date and 01/01/1979). If the amount is less, the date is in the past, so the test label past will be displayed, if not, future is displayed.