-1

How do i send millisecond(1568895389) value for date and time Datatype field values using RestAPI in servicenow

Moni
  • 1
  • 1

1 Answers1

2

You can use the below code to cater to the requirements.

1) To convert a value from a date field to MS.

var gdt = new GlideDateTime();
gdt.setValue(current.getValue('date_type_field'));
var ms = gdt.getNumericValue();
gs.print(ms);

This will print the value of date field in MS. Which you can use anywhere in ServiceNow or Outside.

2) To convert MS to Date

Just pass the values you're getting from your API to "epochString" variable and it should be fine.

var epochString = "1520577092413";
var gdt = new GlideDateTime();
gdt.setNumericValue(epochString);
gs.print(gdt.getValue());

Regards

Ishaan S
  • 51
  • 4
  • This is a great answer for going back and forth between ms and GlideDateTime within ServiceNow, but doesn't actually address a critical part of the question: how to do this via the REST API? So far as I know, the answer to that question depends on where you're coming from, as you probably will need to convert on that end. – Joey Sep 25 '19 at 19:11
  • How can i send using Rest API.While create contacts i have custom field as Date , need to send ms valus for this – Moni Oct 29 '19 at 06:32
  • You can simply pass the variable holding the ms value using the restAPI. – Ishaan S Oct 31 '19 at 04:43