Convert Date Format of date coming in JSON Payload

Ajay37
Tera Contributor

Hello All,

 

We are receiving a payload from 3rd party application. Using that payload, we are submitting a request by mapping key value pairs to variables on the catalog item. We have date parameters in payload and we need to map them to Date type variables. We are receiving date format in payload as "28-Oct-2022", but date variable is accepting format "yyyy-MM-dd".  I have used below script to convert format, but if we give future date or previous date like "27-Oct-2022" or "29-Oct-2022", the value in the date variable is filling with current date irrespective of what received in payload.

 

var chgDate = "29-Oct-2022";
function dateConv(chgDate) {
        var gd = new GlideDate();
		gd.setValue(chgDate);
		return gd.getByFormat("yyyy-MM-dd");
    }

 

Thanks in Advance

1 REPLY 1

Tony Chatfield1
Kilo Patron

Hi, I think you will need setDisplayValue()
if you have any issues with TZ, you should be able to append a TZ to your date like this

var chgDate = "13-Oct-2022";
chgDate = chgDate + ' NZDT';

var gd = new GlideDate();
gd.setDisplayValue(chgDate, 'dd-MMM-yyyy Z');
gs.info(gd);