How to get today date in SANDBOX using client script? I tried the below things but

DINESH CHINNAD1
Giga Expert

Hi,

 

I am new to Servicenow


var today=new Date(); //by using these gives output as UTC form date and time, so i am unable to macth this date with my input whatever i gave in the form

 

var a= now();

var b=nowDateTime();

var right_now=g_form_Date_Time;

 

and also i tried Glide System, Ajax and some other things . Glide System(gs) and Current does not supported by SANDBOX...

 

and tried few more things but i am not able to find???

 

My question is i want to accept the Date of Birth of a person with past and present date only (current date) it will not accept the future date.....

 

Can anyone Guide me....

 

Thanks in Advance...

10 REPLIES 10

Harish Murikina
Tera Guru

Hi Dinesh,



                    Write this below script onchange of DOB field.


 


function onChange(control, oldValue, newValue, isLoading)


{


  if(isLoading)


  {


  return;


  }


 


  var ga = new GlideAjax('includescriptname');


  ga.addParam('sysparm_name','dateFunction');


  ga.addParam('dob_date', newValue);


  ga.getXML(HelloWorldParse);


 


  function HelloWorldParse(response)


  {


  var answer = response.responseXML.documentElement.getAttribute("answer");


  if(answer>=0)


  {


  return true;


  }


  else


  {


  alert("please enter valid DOB");



  return false;


  }


 


  }


 


}





Writhe this code in includescript


_____________________________



var selectingdate = this.getParameter('dob_date');


var currentdate=gs.now();


var answer = gs.dateDiff(currentdate,selectingdate,true);


return answer;