- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2020 07:15 AM
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2020 07:36 AM
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);
Let me know if this is what you are looking for?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2020 07:36 AM
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);
Let me know if this is what you are looking for?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2020 08:06 AM
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.