How to get day and month, Year
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2019 10:25 AM
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';
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2019 12:02 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2019 12:06 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2019 12:13 PM
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';
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2019 12:14 PM
Yes.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2019 01:15 PM
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