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

kush_bajpai
Tera Contributor
Hi,
 
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
 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you need to convert it to normal Date/time and then compare

Regards
Ankur

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

Hi @Ankur Bawiskar 

 

So basically i have a Due Date field which display as 2021-12-31 06:00:00 but when i saw show xml and see it displays as: 20211231T140000Z

 

So what i am trying to achieve is i am trying to pull a list of records which is greater  than today, i tried using dateGR.addEncodedQuery('due_date_time>javascript:gs.beginningOfToday()'); it did not worked

Hi,

if the field is date/time then it should not store in that format i.e. ISO

it should store in normal date/time format

Did you check who updated the due date with that format.

Is this happening for multiple records or only few?

Regards
Ankur

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