- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2017 03:41 PM
Hello,
I'm trying to automatically set a due date field to whatever day is chosen but I want the time to ALWAYS be at 11:59 pm (last hour of due date). The code I'm using is placed on a task box inside a workflow. The result I'm getting is not what I'm looking for. Does anybody know if this code is the problem?
//current.comments = "Due date proposed: " + current.variables.due_date; var dateDueDate = due_date.toString()+ ' 23:59:59'; var dueDate = new GlideDateTime(dateDueDate); var dayOfWeek = parseInt(dueDate.getDayOfWeekLocalTime()); dueDate.setDisplayValue(dateDueDate, "yyyy-MM-dd HH:mm:ss"); dateString = "dd/mm/yyyy"; current.due_date = current.variables.due_date; var gdt = current.due_date.getGlideObject(); gdt.addDaysUTC(1);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2017 02:46 PM
this is the correct answer:
var dateDueDate = current.due_date;
var dueDate = new GlideDateTime(dateDueDate);
var arrDate = [];
arrDate = dueDate.toString().split(' ');
current.due_date.setDisplayValue(arrDate[0]+ ' 23:59:59','yyyy-MM-dd HH:mm:ss');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2017 03:46 PM
If your date field is a Date and Time type of field, it will store the time in UTC time zone. You can do something like:
var dateTimeObj = new GlideDateTime(current.your_date_field);
var myDate = dateTimeObj.getLocalDate() + " 23:59:59");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2017 08:10 AM
Hi Edwin,
But where are you setting the due_date field to the new value? And in your code, aren't you dealing with a date/time format all the time and end up adding the " 23:59:59" at the end?
When adding you recommended code as shown below,
//current.comments = "Due date proposed: " + current.variables.due_date;
/*var dateDueDate = due_date.toString()+ ' 23:59:59';
var dueDate = new GlideDateTime(dateDueDate);
var dayOfWeek = parseInt(dueDate.getDayOfWeekLocalTime());
dueDate.setDisplayValue(dateDueDate, "yyyy-MM-dd HH:mm:ss");
dateString = "dd/mm/yyyy";
*/
var dateTimeObj = new GlideDateTime(current.due_date);
var myDate = dateTimeObj.getLocalDate() + " 23:59:59";
current.due_date = current.variables.due_date;
var gdt = current.due_date.getGlideObject();
gdt.addDaysUTC(1);
I get the following result on the targeted field:
It seems as if it is adding the actual string value as an integer rather than concatenating the string

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2017 07:22 PM
Please check if this helps.
current.dueDate = current.dueDate.toString().split(' ')[0]+ ' ' +'23:59:59';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2017 08:47 AM
Hi Shishir,
When placing your code as shown below, i get the following result.
//current.comments = "Due date proposed: " + current.variables.due_date;
/*var dateDueDate = due_date.toString()+ ' 23:59:59';
var dueDate = new GlideDateTime(dateDueDate);
var dayOfWeek = parseInt(dueDate.getDayOfWeekLocalTime());
dueDate.setDisplayValue(dateDueDate, "yyyy-MM-dd HH:mm:ss");
dateString = "dd/mm/yyyy";
*/
current.dueDate = current.dueDate.toString().split(' ')[0]+ ' ' +'23:59:59';
current.due_date = current.variables.due_date;
var gdt = current.due_date.getGlideObject();
gdt.addDaysUTC(1);