Compare date fields with different format in client script

MercBuilding
Giga Guru

Hi,

  I have requirement to remove option from select box if 'refresh date' field has future date. The 'refresh date' variable is inside multi row variable set, so iam unable to use it in normal client scripts to getvalue of refresh date and then write a script include to compare date with today or future. So in the same client script i need to compare the refresh date with today date and remove the option. I tried below code.

/// Getting today date

var today = new Date();
today.setDate(today.getDate()); 

var today_date_str = formatDate(today, g_user_date_format);// This is giving me in dd-mm-yyyy format

 

I tried to do the same with form variable refresh date and it is passed from alm_hardware table through client script. as toString().


var nextRefreshDate_str=new Date();
nextRefreshDate_str.setDate(nextRefreshDate);
nextRefreshDate_str=formatDate(nextRefreshDate_str, g_user_date_format);

 

When i try above code it is throwing 'There is a javascript error in your console.'. Please let me know how to fix this issue.

 

Appreciate your help!!

Thanks!

var today_date_str = formatDate(today, g_user_date_format); ---> this gives me the format dd-MM-yyyy

the variable 'refresh date' is populated from alm_hardware table which has format as 'yyyy-MM-dd'. 

I tried changing variable date format 

3 REPLIES 3

Ravi Chandra_K
Kilo Patron
Kilo Patron

Hello @MercBuilding 

Greetings!

so the issue would resolve if both date formats are same?

I had similar formatting issue earlier. refer the below script if it could be of anu help:

https://www.servicenow.com/community/hrsd-forum/getbyformat-is-not-working-as-expected/td-p/1326395/...

If my answer helped you in any way, please mark this answer as helpful and correct!!

Regards,

Ravi Chandra.

Ravi Chandra_K
Kilo Patron
Kilo Patron

Hello @MercBuilding 

Any feedback on my reply?

Help others to find a correct solution by marking the appropriate response as correct answer and helpful!!

 

Kind Regards,

Ravi Chandra.

Hi @Ravi Chandra_K ,

   As i said in the post i need to get this in client script i will not be able to call another script include in the same client script. Please let me know if i can do anything on client side only.