How to get actual date and time values in rest api

lucky6
Tera Contributor

I am trying to send updated cases everyday through scripted rest api but here the problem is I am getting date and time values in GMT timezone but I wanted the data in EST timezone.

Can someone help me whether it is possible or not to get date and time in actual display value(EST) instead of GMT?

Thanks in advance..

4 REPLIES 4

Robbie
Kilo Patron
Kilo Patron

Hi @lucky6,

 

There's a system parameter you can add to your URI to retrieve the display value.

sysparm_display_value=true

 

If you want to retrieve both the sys_id and display value, add the following to your URI

sysparm_display_value=all

 

For more info: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0546240

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

 

lucky6
Tera Contributor

Hi @Robbie ,

Still i am not getting exact date and time in response..here i can see 5hrs difference time..

Hi @lucky6,

 

If I understand you correctly, you have written a Scripted Rest API which is being called. Within this script, you are passing various case data including some date/time fields. 

Can you share the segment of your script where you are passing the date/time fields?

 

With no visibility as yet, you basically need to do something similar to the below:

 

var timeNowUSETimezone = your_date_time_field;
timeNowUSETimezone.setTimeZone('US/Eastern');
var value_to_pass_via_api = timeNowUSETimezone.getDisplayValue();
 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

Robbie
Kilo Patron
Kilo Patron

Hi @lucky6,

 

Did you see my earlier response and solution? 

If I understand you correctly, you have written a Scripted Rest API which is being called. Within this script, you are passing various case data including some date/time fields. 

Can you share the segment of your script where you are passing the date/time fields?

 

With no visibility as yet, you basically need to do something similar to the below:

 

var timeNowUSETimezone = your_date_time_field;
timeNowUSETimezone.setTimeZone('US/Eastern');
var value_to_pass_via_api = timeNowUSETimezone.getDisplayValue();
 

@lucky6 - To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie