How to compare date field value with current date in client script of scoped application?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-02-2022 02:15 AM
I have written bellow script: Not getting desired output
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var today= new Date();
var strtDate = formatDate(today, g_user_date_format);
var end = g_form.getValue('start_date');
if(end > strtDate)
{
g_form.showFieldMsg('start_date',"Date is in future", 'info', false);
}
else
{
g_form.showFieldMsg('start_date',"Date is in past", 'warning', false);
}
}
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-02-2022 02:25 AM

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-02-2022 02:28 AM
Hi,
Can you try below sample code
var start = g_form.getValue('start_date'); //give your field name
var today = new Date();
today.setDate(today.getDate());
if (start.toString() <= today.toString()){
g_form.addErrorMessage("Planned Start Date cannot be less than 24 hrs ahead in future.");
return false;
}
Regards,
Sumanth
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-02-2022 04:56 AM
Hi Sumanth,
Thanks for your reply but it didn't work for me.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-22-2025 08:57 AM
Hey, You can Try this
var today = new Date();
var dateField = new Date(g_form.getValue('date_field'));
if (today > dateField ) {
var proceed = confirm("The selected Date is in the past. Are you sure you want to continue?");
if (!proceed) {
return false;
}
}
You can modify the script accordingly. But make sure the format of the New date and the Date field is same. Please mark my answer as Helpful if you found it helpful.