Check if current date is in between two dates?

RK41
Tera Expert

Hi,

  • I have two new custom field in incident table called "Start date/time" and "End date time".
  • I created one UI Page that comes when we click the UI Action button in incident form.
  • I have only one message textbox field in UI Page with "Save" and "Cancel" button in the form.

So when user enters any message in textbox and click the save button in UI Page, I have to do the below validation.

Check current date/time is between "Start date/time" and "End date/time".

If Yes, Popup one alert with message of "Successfully added the message in comments" and save the message into comments.

If No, Popup one alert with message of "You can't add any message, because the time is crossed".

 

I used the below script, but it's not worked. Please help me to fix this issue.

//UI Page Client script:- 

var start = g_form.getValue("start_date_time");
var end = g_form.getValue("end_date_time");
var nowDate = new Date(); //getting current date

if(nowDate.getNumericValue() > start.getNumericValue() && nowDate.getNumericValue() < end.getNumericValue()){
// My alert message for yes
}
else{
// My alert message for no
}

 

Thanks,

Raj

 

1 ACCEPTED SOLUTION

Thanks Mohith. It's worked as I expected.

 

I have used the below code.

var start = g_form.getValue("start_date_time");
var end = g_form.getValue("end_date_time");
    
var startDT = new Date(start);
var endDT = new Date(end);
var nowDate = new Date();

if (nowDate > startDT && nowDate < endDT) {
// My alert message for yes
}

else{
// My alert message for no
}

 

Thanks,

Raj

View solution in original post

2 REPLIES 2

Mohith Devatte
Tera Sage
Tera Sage

Helllo Can you try the below code

var start=g_form.getValue("start_date_time");

var end = g_form.getValue("end_date_time");

var nowDate = new GideDateTime();

var nowStartDate = new GlideDateTime(start);

var nowEndDate = new GlideDateTime(end); if(nowDate.getDate()>nowStartDate.getDate() && nowDate.getDate() < nowEndDate.getDate())

{ // My alert message for yes

} else{ // My alert message for no

}

Mark my answer correct if it helps you

Thanks Mohith. It's worked as I expected.

 

I have used the below code.

var start = g_form.getValue("start_date_time");
var end = g_form.getValue("end_date_time");
    
var startDT = new Date(start);
var endDT = new Date(end);
var nowDate = new Date();

if (nowDate > startDT && nowDate < endDT) {
// My alert message for yes
}

else{
// My alert message for no
}

 

Thanks,

Raj