Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

user_calendar_event table and checking dates

Emars
Kilo Contributor

Hi All,

Does anyone know how to convert the date/time below to a regular date format? currently in the user_calendar_event the start/end date is stored like the string below but i need convert it to a regular date time such as 2022-02-08 8:21:59. I have built a simple ui page that allows a tech to schedule a user, they select the date/time using their timezone EST in this case once they save it it creates a entry in the calendar event table. What I am now trying to do is when the press save check if the user they selected is available at that date/time using the code below. problem i am having is the date/time stored as "20220208T140016Z"

Date stored as: 20220208T140016Z  (UTC Time)

UI page:

find_real_file.png

Code that looks like it will work, the startDateTime and endDateTime i put it in that format to test, need find a way to convert "20220208T140016Z  " to format "YYYY-mm-dd hh:mm:ss"

//Check dates between
var startDateTime = new GlideDateTime('2022-02-08 09:20:59');

startDateTime.addSeconds(-3600);

//-1 hour, if they select 9 am they should get a error since the start time is 8:20 and falls between, if they select 9:30 still gets error because still falls between
gs.log('startDateTime is: ' + startDateTime)

var endDateTime = new GlideDateTime('2022-02-08 10:20:59');

var requestedTime = new GlideDateTime('2022-02-08 8:21:59'); //This is the date it is checking
//try substracting the numeric value - 1 hour to change the start time

if (requestedTime.getNumericValue() < endDateTime.getNumericValue() && requestedTime.getNumericValue() > startDateTime.getNumericValue()) {

    // within
    gs.log('User is booked try again');

}

else {

    // outside date
    gs.log('User is not booked set schedule');
}

 

 

 

 

1 REPLY 1

DrewW
Mega Sage

I see you have two options

//You can test this as a background script.
//********** Option 1
var reg = /(\d{4})(\d{2})(\d{2}).(\d{2})(\d{2})(\d{2})/i
var dtInfo = reg.exec("20220208T140016Z");
var dts = dtInfo[1] +
    "-" + dtInfo[2] + 
    "-" + dtInfo[3] + 
    " " + dtInfo[4] +
    ":" + dtInfo[5] +
    ":" + dtInfo[6];
gs.print(dts);

var dt = new GlideDateTime(dts);
gs.print(dts);



//********** Option 2
var dtInfo2 = ("20220208T140016Z").replace("T", "").replace("Z", "");
var dt2 = new GlideDateTime();
dt2.setValueUTC(dtInfo2, "yyyyMMddHHmmss");
gs.print(dt2);