We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Why setDisplayValue in glide date time object adding 6 hrs?

Manikantahere
Tera Contributor
var startdate =  2024-11-13
var gdtStartDate = new GlideDateTime();
  gs.print(gdtStartDate);
 gdtStartDate.setDisplayValue( startdate + ' 00:00:00');
 
Why it is printing date with 6 hrs.? as it is supposed to print with 2024-11-13 00:00:00?
2024-11-13 06:00:00
7 REPLIES 7

Tapish Sharma1
Kilo Sage

Make your startdate var a string

thats typo here but i did so in background script.

 var empstartdate = "2024-11-13" ;
 var gdtStartDate = new GlideDateTime();
  gs.print(gdtStartDate);
 gdtStartDate.setDisplayValue(empstartdate+ ' 00:00:00');
 gs.print(gdtStartDate);
 
 
restult :
 
*** Script: 2024-11-05 12:09:57
*** Script: 2024-11-13 06:00:00

Juhi Poddar
Kilo Patron

Hello @Manikantahere 

There is two small changes needed in the code:

  1. variable startdate should be a string therefore change it to "2024-11-13"
  2. Should be setValue instead of setDisplayValue 
Here is the update code:

 

 

var startdate = "2024-11-13";
var gdtStartDate = new GlideDateTime();
gdtStartDate.setValue(startdate + ' 00:00:00');
gs.print(gdtStartDate);

 

 

 output preview:
JuhiPoddar_0-1730808479164.png

 

 "If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"
 
Thank You
Juhi Poddar
 
Thank You!
Juhi Poddar