How would I fix this date/time issue?

e_wilber
Tera Guru

Our instance date/time is below:

e_wilber_1-1683766299978.png

 

 

I am trying to set Start Travel Time to the same value as Mobile Travel Start but you can see it's doing some level of conversion. How do I make it keep the original?

 

Note - Mobile Travel Start is a text field and Start Travel Time is a date/time field. From my mobile app there's an issue with date/times so I'm not actually able to map my date/time field to Start Travel Time directly (it just stores an empty field). My work around was to store the data in a text field first so I could manipulate it and add it back.

 

I have tried

var travelStart = new GlideDateTime(current.u_mobile_travel_start);
current.u_travel_start = travelStart;
 
as well as
current.u_travel_start = current.u_mobile_travel_start;

They both have the same result where it looks like it's setting it to 3pm even though I selected 7pm central time on my phone.

 

e_wilber_0-1683766291393.png

 

2 REPLIES 2

KB18
Tera Guru
Tera Guru

Dear @e_wilber 

 

Please try using the below code, 

Option 1 : 

var travelStart = new GlideDateTime(current.u_mobile_travel_start);

gs.info('date: ' + travelStart.getDisplayValue());

current.u_travel_start = travelStart.getDisplayValue();
 
Option 2 :
var gdt = current.u_mobile_travel_start.getGlideObject();
GlideSession.get().setTimeZoneName('US/Eastern');
gs.info('In ' + GlideSession.get().getTimeZoneName() + ": " + gdt.getDisplayValue());



 

Please hit the thumb Icon and mark as correct in case I help you with your query!!!
- Kailas

Pushkar-Snow
Mega Guru

Hi @e_wilber ,

 

If you want to display the date as it is which you are storing in the Mobile Travel start field (String type) then you can just use setDisplayValue to set value for Start Travel Time field. Please refer below code:

 

<field name>.setDisplayValue(<date string want to set for this field>);

start_travel_time .setDisplayValue("2023-05-10 19:32:00");

 

Please ask if you face any problem. 

If I am able to help you with your question, Please click the Thumb Icon and mark as Correct. 

 

Regards,

Pushkar