How to convert planned start date (2024-09-18 23:59:59) into 20240918T235959Z ?

Virendra K
Kilo Sage
Hi All,
 
Need some help on calculating the Dates, I am trying to fetch the "planned start date" and want to compare with "start date time" (which is Schedule Date/Time type) .
I see the "start date time" output is stored as  20240408T044500Z
Now i want convert planned start date (2024-09-18 23:59:59) that as 20240918T235959Z
Can anyone please help me how to do this?
 
Thanks,
Virendra
1 ACCEPTED SOLUTION

Gangadhar Ravi
Giga Sage
Giga Sage

@Virendra K You can try something like below script. I tried in PDI and it worked fine.

 

var plannedStartDateStr = '2024-09-18 23:59:59';
var gdtPlannedStart = new GlideDateTime(plannedStartDateStr);
var formattedDate = gdtPlannedStart.getDate().getByFormat('yyyyMMdd') + 'T' + gdtPlannedStart.getTime().getByFormat('HHmmss') + 'Z';
gs.info('Formatted Planned Start Date: ' + formattedDate); 

View solution in original post

2 REPLIES 2

Anantha Gowrara
Kilo Sage

Hi @Virendra K, I don't think service now provides any method to convert to "yyyy-MM-dd'T'HH:mm:ss.SSSZ" however you can still do vice-versa that is converting from "yyyy-MM-dd'T'HH:mm:ss.SSSZ" format to "yyyy-MM-dd HH:mm:ss" using GlideDateTime API.Once date is converted you can use datediff method to compare both dates.

Gangadhar Ravi
Giga Sage
Giga Sage

@Virendra K You can try something like below script. I tried in PDI and it worked fine.

 

var plannedStartDateStr = '2024-09-18 23:59:59';
var gdtPlannedStart = new GlideDateTime(plannedStartDateStr);
var formattedDate = gdtPlannedStart.getDate().getByFormat('yyyyMMdd') + 'T' + gdtPlannedStart.getTime().getByFormat('HHmmss') + 'Z';
gs.info('Formatted Planned Start Date: ' + formattedDate);