Why Date is getting preponed 1 day of given input date using GlideDateTime ?

Virendra K
Kilo Sage

Hi All,

 

I am facing weird scenario. I am using script include and getting planned start and end as a input from client script.

Please refer below script for reference. Suppose, if I have selected input date as 2024-10-26 03:10:05 (planned start) to 2024-10-26 10:08:06 (planned end). I am using GlideDateTime to set the time of the date from the mid night (00:00:01) to end of the day (23:59:59). The intention is to cover all the time slots on that day which is present in the table data.

When I put the logs notes, I noticed that when I am fecting the dates in SI is showing as expected but when I am trying to set the timings to the given dates(as mentioned above), Planned Start date is getting preponed to 25th Oct.

 

What is the reason its only changing Planned start date , not Planned end date though I am using same conversion/functionality to set the timings ? (refer the snaps and script lines given as below) 

 

In line# 6 and 7, I am receiving Dates from client script  (refer snap 1)

In line# 9 and 10, setting timings to given dates.

When I checked logs its showing preponed date ( refer snap 2)

VirendraK_0-1730011397813.png

 

VirendraK_1-1730012132662.png

 

==========================================================================

// here are the few script lines given 

 

var checkMoratoriumDates = Class.create();
checkMoratoriumDates.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getallValues: function() {
        var output = [];

        var plannedStart = new GlideDateTime(this.getParameter("sysparm_startDt")); // Planned start date
        var plannedEnd = new GlideDateTime(this.getParameter("sysparm_endDt")); // Planned end date
        gs.log('Vir: Start and End dt 1st= ' + plannedStart + " to " + plannedEnd);
        plannedStart.setDisplayValue(plannedStart.getDisplayValue().split(" ")[0] + " 00:00:01");
        plannedEnd.setDisplayValue(plannedEnd.getDisplayValue().split(" ")[0] + " 23:59:59");

        var timeZone = this.getParameter("sysparm_timeZone");
        var divisionVal = this.getParameter("sysparm_division");

        gs.log('Vir-TCS: Start and End dt = ' + plannedStart.getDisplayValue() + " to " + plannedEnd.getDisplayValue());
 
========================================================================================
Regards,
Virendra

 

1 ACCEPTED SOLUTION

Najmuddin Mohd
Mega Sage

Hi @Virendra K ,

Can you check the below script:

var plannedStart = new GlideDateTime(this.getParameter("sysparm_startDt")); // Planned start date
var plannedStartDate = plannedStart.getDate();

var plannedEnd = new GlideDateTime(this.getParameter("sysparm_endDt")); // Planned end date
var plannedEndDate = plannedEnd.getDate();

gs.log('Vir: Start and End dt 1st= ' + plannedStart + " to " + plannedEnd);

var newPlannedStart = new GlideDateTime(plannedStartDate + " 12:00:00");
var newPlannedEnd = new GlideDateTime(plannedEndDate + " 23:59:00");

gs.log('Vir: Start and End dt 1st= ' + newPlannedStart + " to " + newPlannedEnd);

 

 

From Scripts - background, I have validated it.

 

var plannedStart = new GlideDateTime(); // Planned start date
var plannedEnd = new GlideDateTime();
plannedEnd.addDaysUTC(2);


//var plannedStart = new GlideDateTime(this.getParameter("sysparm_startDt")); // Planned start date
var plannedStartDate = plannedStart.getDate();

//var plannedEnd = new GlideDateTime(this.getParameter("sysparm_endDt")); // Planned end date
var plannedEndDate = plannedEnd.getDate();

gs.log('Vir: Start and End dt 1st= ' + plannedStart + " to " + plannedEnd);

var newPlannedStart = new GlideDateTime(plannedStartDate + " 12:00:00");
var newPlannedEnd = new GlideDateTime(plannedEndDate + " 23:59:00");

gs.info(newPlannedStart + '  ----   ' +  newPlannedEnd);

Output:

*** Script: Vir: Start and End dt 1st= 2024-10-27 09:26:18 to 2024-10-29 09:26:18
*** Script: 2024-10-27 12:00:00  ----   2024-10-29 23:59:00

 

 

If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.

View solution in original post

2 REPLIES 2

Najmuddin Mohd
Mega Sage

Hi @Virendra K ,

Can you check the below script:

var plannedStart = new GlideDateTime(this.getParameter("sysparm_startDt")); // Planned start date
var plannedStartDate = plannedStart.getDate();

var plannedEnd = new GlideDateTime(this.getParameter("sysparm_endDt")); // Planned end date
var plannedEndDate = plannedEnd.getDate();

gs.log('Vir: Start and End dt 1st= ' + plannedStart + " to " + plannedEnd);

var newPlannedStart = new GlideDateTime(plannedStartDate + " 12:00:00");
var newPlannedEnd = new GlideDateTime(plannedEndDate + " 23:59:00");

gs.log('Vir: Start and End dt 1st= ' + newPlannedStart + " to " + newPlannedEnd);

 

 

From Scripts - background, I have validated it.

 

var plannedStart = new GlideDateTime(); // Planned start date
var plannedEnd = new GlideDateTime();
plannedEnd.addDaysUTC(2);


//var plannedStart = new GlideDateTime(this.getParameter("sysparm_startDt")); // Planned start date
var plannedStartDate = plannedStart.getDate();

//var plannedEnd = new GlideDateTime(this.getParameter("sysparm_endDt")); // Planned end date
var plannedEndDate = plannedEnd.getDate();

gs.log('Vir: Start and End dt 1st= ' + plannedStart + " to " + plannedEnd);

var newPlannedStart = new GlideDateTime(plannedStartDate + " 12:00:00");
var newPlannedEnd = new GlideDateTime(plannedEndDate + " 23:59:00");

gs.info(newPlannedStart + '  ----   ' +  newPlannedEnd);

Output:

*** Script: Vir: Start and End dt 1st= 2024-10-27 09:26:18 to 2024-10-29 09:26:18
*** Script: 2024-10-27 12:00:00  ----   2024-10-29 23:59:00

 

 

If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.

Thanks for the reply and help @Najmuddin Mohd .

I made the changes accordingly for dates/time.