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

Finally I was able to get going. The issue I found out was  when getting display value format is changed to 

02-20-2020 23:09:18 and I needed YYYY-MM-DD HH:MM so it was getting rejected.


Thank you very much all of you for helping me out resolve the issue.

Thanks,

Rajan Mehta


Not sure what endpoint you're using in Dynatrace, but it appears it takes an integer not date/time for the start time.  https://www.dynatrace.com/support/help/extend-dynatrace/dynatrace-api/environment-api/events/post-ev...

RichGK1
Mega Expert

GlideDate and the function getByFormat will convert from one format to another.

https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=c_GlideDateScopedAPI.dita

var gd = new GlideDate(); 
gd.setValue('2015-01-01');
gs.info(gd.getByFormat("dd-MM-yyyy"));

 

Hello Rich

Thanks for your tips. I am following it and can you please advise, what do I need to change here?

When I execute this I am getting following results. 

I should get (or rather expecting) below.

2020-02-21 07:09:18  ==> get converted to 2020-02-21 07:09 (Date format not String)

find_real_file.png

 

find_real_file.png