Convert date format in gliderecord

Karine_M
Tera Guru

Hi,

 

I need to use a script to retrieve schedules entries with an end date later than today.
The problem is that the end_date_time field isn't in the usual date format (20251231T235900), and I can't compare it to the current date in my gliderecord. Can anyone help?

 

Karine

 

the script :

 
var today = gs.beginningOfToday();
var nbSchedule = 0;
    gs.info('today: ' + today ); // format : 2025-06-18 00:00:00
var gsp = new GlideRecord('cmn_schedule_span');
        gsp.addQuery('end_date_time','>',today);
        gsp.groupBy('schedule');
        gsp.query();
while (gsp.next()) {
       gs.info('schedule: ' + gsp.end_date_time);
    nbSchedule++;
    }
       gs.info('nbSchedule: ' + nbSchedule);
1 ACCEPTED SOLUTION

Ehab Pilloor
Mega Sage

Hi @Karine_M,

 

You can try the following code:

var today = new GlideDateTime();
today.setDisplayValue(gs.beginningOfToday().getDisplayValue());

var formattedToday = today.getDate().getByFormat('yyyyMMdd') + 'T000000';

gs.info('Formatted today: ' + formattedToday);

var nbSchedule = 0;
var gsp = new GlideRecord('cmn_schedule_span');
gsp.addQuery('end_date_time', '>', formattedToday);
gsp.groupBy('schedule');
gsp.query();

while (gsp.next()) {
    gs.info('Schedule: ' + gsp.end_date_time);
    nbSchedule++;
}
gs.info('nbSchedule ' + nbSchedule);

 

Regards,

Ehab Pilloor

View solution in original post

2 REPLIES 2

Ehab Pilloor
Mega Sage

Hi @Karine_M,

 

You can try the following code:

var today = new GlideDateTime();
today.setDisplayValue(gs.beginningOfToday().getDisplayValue());

var formattedToday = today.getDate().getByFormat('yyyyMMdd') + 'T000000';

gs.info('Formatted today: ' + formattedToday);

var nbSchedule = 0;
var gsp = new GlideRecord('cmn_schedule_span');
gsp.addQuery('end_date_time', '>', formattedToday);
gsp.groupBy('schedule');
gsp.query();

while (gsp.next()) {
    gs.info('Schedule: ' + gsp.end_date_time);
    nbSchedule++;
}
gs.info('nbSchedule ' + nbSchedule);

 

Regards,

Ehab Pilloor

Thank you very much for this quick response. It works perfectly!

 

Regards,

Karine