Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Ankur Bawiskar
Tera Patron

Consider a requirement to validate if the user selects a time in the date/time variable between 11 AM and 4 PM.

You can use the onChange catalog client script with the following logic. It handles for every timezone.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    g_form.hideFieldMsg('my_datetime');
    var myDate = new Date(getDateFromFormat(newValue, g_user_date_time_format));
    var hourValue = myDate.getHours();
    if (hourValue > 11 && hourValue < 16) {
        // valid
    } else {
        g_form.showFieldMsg('my_datetime', 'Time should be between 11am to 4pm', 'error');
    }

}

This checks the time is between 11am to 4pm based on logged in user timezone.

Output: I selected GMT & then selected Los Angeles time zone and it gave me the error based on requirement.

 

AnkurBawiskar_1-1737548758196.gif

 

 

 

Comments
Appu
Tera Guru

@Ankur Bawiskar 
I hava a requirement where date/time variable when selected should be adjusted according to UTC time zone always.

 

 

Please provide a solution
Thanks in advance

Version history
Last update:
‎01-22-2025 04:27 AM
Updated by:
Contributors