Using GlideDate() in a Scheduled Job Script

ParkPants
Tera Contributor

Hi all,

I have a Scheduled Job script in my instance where I need to get the current date in 'MM-DD-YYYY' format with no hyphens in between the numbers. To accomplish this, I thought to use GlideDate but the results aren't really to my liking. This may have been because GlideDate is only documented for Server-Scoped and not for Server-Global like I'm using it for so instead of returning a string, it returned an object. This caused me to workaround the issue with the following code to get what I wanted.

var test = JSON.parse(JSON.stringify(new GlideDate().getByFormat('MM-dd-yyyy'))).replace(/-/gi, '');

My question is, is there a better way of achieving what I need here? How would this same process look if I used GlideDateTime instead?

Thanks in advance.

1 ACCEPTED SOLUTION

Willem
Giga Sage
Giga Sage

Whoa! The documentation on this seems to be incorrect. If I print typeof you are totally right and it returns object for 'new GlideDate().getByFormat('MM-dd-yyyy')'. toString also did not help.

I am able to parse it to sting by implicit declaration:

var test = new GlideDate().getByFormat('MM-dd-yyyy') + '';
test = test.replace(/-/gi, '');
gs.print(test);

find_real_file.png

 

Let me know if this is what you are looking for?

View solution in original post

2 REPLIES 2

Willem
Giga Sage
Giga Sage

Whoa! The documentation on this seems to be incorrect. If I print typeof you are totally right and it returns object for 'new GlideDate().getByFormat('MM-dd-yyyy')'. toString also did not help.

I am able to parse it to sting by implicit declaration:

var test = new GlideDate().getByFormat('MM-dd-yyyy') + '';
test = test.replace(/-/gi, '');
gs.print(test);

find_real_file.png

 

Let me know if this is what you are looking for?

ParkPants
Tera Contributor

Thanks, that should work fine. I was really just figuring out how to reduce the jank in my code but this is working perfectly and also helps in efficiency.