Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get Day from Date

chanikya
Kilo Sage

Hi,

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var seldate=g_form.getValue('date');
var objdate=new Date(seldate);
var selday=objdate.getDay();
alert(selday);
 if(selday==0||selday==6)
 {
 alert('select business day');
 g_form.setValue('date','');
 }
}

but i am getting "NaN " value in alert.

 

1 ACCEPTED SOLUTION

did you try with the code which i have posted ?

 

Updated Code:

 

var df = g_form.getValue('u_date');
	
	var op=df.split('/');
	var ress=op[2]+'/'+op[1]+'/'+op[0];
	
		var objdate=new Date(ress);
		alert(objdate);
		var selday=objdate.getDay();
		var res = parseInt(selday);
		alert(res);
		if(res==0||res==6)
			{
			alert('select business day');
			
		}

 

Change the field value. if you have a data/time type field then you can follow the same split() to make your data format like yyyy-MM-dd 

 

View solution in original post

29 REPLIES 29

Hi,

The code provided by @Harshvardhan is correct and it should work not sure why it's not working.

However, I have modified the code as below:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var selday=newValue.getDay();
var res = parseInt(selday);
alert(res);
 if(res==0||res==6)
 {
 alert('select business day');
 g_form.setValue('date','');
 }
}

Please try once and let me know if it's working or not..

Regards,

Alok

Harsha script is working good, no problem with that 

i have tested his script in my PDI's  working fine ,  here i didn't uderstand that same script placed in Client environment it giving "NaN" alert message 

 


var seldate=g_form.getValue('date');
var objdate=new Date(seldate);
var selday=objdate.getDay();
var res = parseInt(selday);
alert(res);     alert like "NaN" in client Environment only , working fine in my PDI
if(res==0||res==6)
{
alert('select business day');
g_form.setValue('date','');
}

i tested the code which i have provided and its not giving me NAN on my personal instance. 

My PDI it is working, but in Client Instance it is giving "NaN" value 

find_real_file.png

the change which you have made in the properties , that's the reason you are getting NAN. 

if you can made the changes in below format it will work. 

 

Data Format : yyyy-MM-dd