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

anyway other way is change the format in script itself that would also work. 

 

Sample 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');
			
		}

 

Note: Script has been Tested on PDI and working fine. 

Make the field changes based on what you have on your form. 

 

Vaibhav
Mega Guru

Hi,

Try this

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	
	var dt = g_form.getValue('date');  // add your field here
	
	var ab = dt.split(' ');
	var dte = ab[0];
	
	var op = dte.split('-');
	var op1 = op[2];
	
        alert("Date :: " +op1); // Here 'op1' will give you date & you can use it anyplace

	if(op1 == '00' ||op1 == '06'){	// Here how could be date "00" ?
		alert(' Your Alert Msg');
		g_form.setValue('date',''); // add your field here
	}	
}

Mark it correct/helpful if it helps you

Regards,

Vaibhav Chaudhari

find_real_file.png

 

result is like this 

can you post your current script ?

Thanks

This works fine in my PDI, make sure you have selected the right field for on change field and field is on the form

, this example is for resolved at field

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	
	var dt = g_form.getValue('resolved_at'); 
var objdate= new Date(dt);
var selday=objdate.getDay();
	

	if(selday == '0' ||selday == '6'){	
		alert(' Select a week day');
		g_form.setValue('resolved_at','');
	}	
}