How to add T in between Date and Time format like YYYY:MM:DDTHH:MM:SS

akshay parekar1
Tera Contributor

Continuing to my previous question,

I have a one date/time type variable in my catalog item which is displaying me date/time as per my catalog client script from which i have called a script include.

Now, its populating value like - 2022-08-02 04:13:17

I want this above in different format like- 2022-08-02T04:13:17+0000 (where T and +0000 remain same every time i'm getting this value)

please help me for this one and tell where i need to make changes

My script Include:

var AutoPopulateDate = Class.create();
AutoPopulateDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getDate: function() {
        var daysrequired = this.getParameter('sysparm_days_required');
        var currentDate = new GlideDateTime(gs.now());
        currentDate.addMonths(daysrequired);
        return currentDate;

    },

    type: 'AutoPopulateDate'
});

 

My catalog client script:


function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    alert('Days Required change');
    var ga = new GlideAjax('AutoPopulateDate');
      ga.addParam('sysparm_name', 'getDate');
      ga.addParam('sysparm_days_required', newValue);
      ga.getXML(CallBackFunction);


     

function CallBackFunction(response) {
      var answer = response.responseXML.documentElement.getAttribute("answer");
    alert('return date '+answer);
    g_form.setValue('date',answer);
 
}
   
}

1 ACCEPTED SOLUTION

suvro
Mega Sage
Mega Sage

You can try below

 


var result = answer .replace(" ""T") + "+0000";

 g_form.setValue('date',result);

 

 

View solution in original post

8 REPLIES 8

suvro
Mega Sage
Mega Sage

You can try below

 


var result = answer .replace(" ""T") + "+0000";

 g_form.setValue('date',result);

 

 

yes,it's working, thanks!!

 

Kindly mark my response as correct and helpful so that other users can benefit from this

Hey, but i'm not getting time value and its always populating 00:00:00 after changing my catalog client script

in short, i want my date/time type variable to display as

2022-10-02T05:43:19+0000

But it's displaying always like

2022-10-02T00:00:00+0000

please help in this