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

@akshay parekar 

If it's a date/time variable then it will always hold value in the system format and not in 

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

check this link where I shared solution and try to enhance it further

How to convert current date time into ISO ISO8601 format: yyyy-MM-dd'T'HH:mm:ss'Z

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

the date format 2022-08-02T04:13:17+0000 looks like an ISO date/time format

So if you just replace it with T and 0000 it won't reflect the correct date/time

you can convert the normal date/time to that ISO format

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

yes, by above way its not reflecting correct date/time format

can you please elaborate how to convert to that ISO format

Hi,

If it's a date/time variable then it won't hold data in any other format

So I am not sure if your requirement is still valid or not.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader