How to get day and month, Year

Sironi
Kilo Sage

Hi,

please help me in Date , it could not getting Month and year. displaying undefined 

Business Rule: Incident  , Update, Before

var cdate=current.u_date_needed;
var d = new Date();
var hh = d.getHours();
var date=0;
gs.addInfoMessage(gs.getMessage(hh));---------------------getting correct local user hours -------
var dd = String(d.getDate()).padStart(2, '0');
var mm = String(d.getMonth() + 1).padStart(2, '0'); 
var yyyy = d.getFullYear();
var today=yyyy+'-'+mm+'-'+dd;
gs.addInfoMessage(gs.getMessage(today));         -------------2019-undefined-undefined
gs.addInfoMessage(gs.getMessage(cdate));
if(today>=cdate)
{
if (hh > 7)
{
current.state='Closed Incomplete';
}
}

16 REPLIES 16

i used above script result is 

find_real_file.png

any suggestions ?

Did you try below script? If you do getHours, it will get you the hours based on system timezone and not based on your timezone. You are probably on IST.

 

var cdate=current.u_date_needed;

var gdt = new GlideDateTime();
var today = gdt.getLocalDate();
var hh = gdt.getLocalTime().getByFormat('hh');

gs.addInfoMessage(gs.getMessage(hh));
gs.addInfoMessage(gs.getMessage(today));
gs.addInfoMessage(gs.getMessage(cdt));

if(today>=cdate)
{
if (hh > 7) 
{
current.state='Closed Incomplete'; 
}
}


Please mark this response as correct or helpful if it assisted you with your question.

YES.. THIS IS THE RESULT I GOT IT HERE

 

find_real_file.png

 

 

in My system  date/time is 06-09-2019 00:22 min AM

find_real_file.png

But, what is the timezone set in your servicenow user profile?


Please mark this response as correct or helpful if it assisted you with your question.