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

UTC, 

basically client requirement is , it should take user local date and time

in User profile Timezone what ever it may be, but it should take user local time only 

That's not possible. Servicenow considers local time as user's profile timezone.

And user's always prefer setting the servicenow profile timezone to their own timezone.

Otherwise they will get confused. So you should change yours too. ServiceNow can't identify you computers timezone.


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

So this is the better way for this time?

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

Yes.


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

CAn you suggest me  here please

my Date Needed is : 10-09-2019

so i want to close incident one day before , means on 09-09-2019 at 7AM morning