Need help on Date Conversion to ISOString

shaik_irfan
Tera Guru
Hi,
 
need some help on calculating the Dates, I am trying to fetch the records whose Due Date (which is Schedule Date/Time type) is after today.
 
I see the output is stored as  20220101T020000Z  can anyone please help me how to fetch using script.
I tried as dateGR.addEncodedQuery('due_date_time>javascript:gs.beginningOfToday()'); but it is not working
 
var gdt = new GlideDateTime(); //giving me the current date and time 
 
Now i want convert that as 20220107T020000Z
 
Can anyone please help me how to do this
 
 
1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi Shaik,

 
Please use the below function,
 
function getDateFormat() {
        var gd = new GlideDate();
        var gt = new GlideTime();
        gt.setValue(gt.getHourOfDayUTC() + ':' + gt.getMinutesUTC() + ':' + gt.getSeconds());

 

        var timeStamp = gd.getByFormat("yyyyMMdd") + 'T' + gt.getByFormat("HHmmss") + 'Z';
        return timeStamp;
    }
 
Please mark helpful, if that solved your purpose.
 
Thanks,
Kush

View solution in original post

7 REPLIES 7

Its a Schedule Date/Time type field so its storing in that format only and its same for all the records

then you cannot directly query in addEncodedQuery() because it requires value similar to GlideDateTime

Try to apply filter using filter conditions and then try to copy and use if that works

Regards
Ankur

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

Community Alums
Not applicable

Hi Shaik,

 
Please use the below function,
 
function getDateFormat() {
        var gd = new GlideDate();
        var gt = new GlideTime();
        gt.setValue(gt.getHourOfDayUTC() + ':' + gt.getMinutesUTC() + ':' + gt.getSeconds());

 

        var timeStamp = gd.getByFormat("yyyyMMdd") + 'T' + gt.getByFormat("HHmmss") + 'Z';
        return timeStamp;
    }
 
Please mark helpful, if that solved your purpose.
 
Thanks,
Kush