How to check the date is within 3 months of the current date?

lajklkj
Kilo Contributor

I need to check the date is within 3 months of the current date. I checked it by 90 days but the requirement is for 3 months. I need to check date within 3 months. means its may be either 90 days or 92 days. kindly help me into this.

9 REPLIES 9

lajklkj
Kilo Contributor

My code is given below,


var date1 = g_form.getValue('valid_to');//client script


      var date2=gs.monthsAgo(-3);   //script include



if(date1<date2)


{


alert(date2);


}



my If condition is not executing when I take date1 value "oct-31-2015."


Thats why I also suggested current.sys_created_on>gs.monthsAgo(3)



However, you could do this client side only:



Something like this:


var threeMonthsAgo = new Date();


threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3);



var validTo = new Date(g_form.getValue("valid_to"));


var isValid = ( validTo > threeMonthsAgo ); //true / false



console.log(isValid);


Hi Dan,


my valid_to field is already glidedate type. when I convert it to date it throwing invalid date


dave_slusher
ServiceNow Employee
ServiceNow Employee

I'm not sure I understand the difference between "90 days" and "3 months ago". Are you saying the requirement is to check against the date of the month but three months ago, regardless how many days that was? So today you would be checking against July 5th? How does that work on July 31st when there is no valid date for three months prior?


I need to convert a string "mon-dd-yyyy" in glideDate.