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 11:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2019 11:36 AM
any suggestions ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2019 11:40 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2019 11:43 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2019 11:54 AM
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.