How to convert Date YYYY-MM-DD HH:MM:SS format to YYYY-MM-DD HH:MM format

Rajanmehta
Mega Guru

hello we are on Newyork.

I have a need to convert default time format  YYYY-MM-DD HH:MM:SS in Servicenow  to YYYY-MM-DD HH:MM format. (Excluding Seconds), because the tool, we are sending this accepts only  YYYY-MM-DD HH:MM format.

How can I do that? The final value should be of Date time only.

So 2020-02-20 23:09:18  should return 2020-02-20 23:09

Please advise.

Thanks,

Rajan 

 

1 ACCEPTED SOLUTION

JSON always send date as a string.  Which would make jacebeson's post below make sense that the API is looking for an integer.

View solution in original post

13 REPLIES 13

Brian Lancaster
Tera Sage

I'm writing this like it is in a business rule but you can convert it to what ever type of script your are using.

var dateStr = current.getDisplayValue('field name').toString();
var res = str.slice(0, 16);

Then you would send res variable but of course you can change that to something more meaningful.

 

Knight Rider
Mega Guru

Hi Rajan,

please try below this worked perfect for me!!

var gdt =GlideDateTime().toString();

var newDate = gdt.slice(0,gdt.length()-3);

gs.log(" gdt : " +gdt);

gs.log(" newDate : " +newDate);

 Please  see snippet for result 

find_real_file.png

Thanks!!

Hello Knight,

I get your point. Only issue is the new value returned is String and I have to send the data in date format. (YYYY-MM-DD HH:MM). Also if I convert back from String to Date it goes into YYYY-MM-DD HH:MM:SS format.

so if you can guide me how do I correct this, that would be great.

Thanks,

Rajan 

What is your method for sending the data to the other system?