Format Date GlideDateTime to dd.mm.yyyy ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2018 02:42 AM
I am running a server side script which calculates the last day of the month.
var gdt = new GlideDateTime();
gdt.addMonthsUTC(-1);
var month = gdt.getMonthUTC();
var year = gdt.getYearUTC();
var d = new Date(year, month + 1, 0);
gs.print(d); // last day of month
My current output looks as follows:
Wed Feb 28 2018 00:00:00 GMT-0800 (PST)
What I would love to receive is:
28.02.2018
I would love to avoid using stupid replace scripts or regex. There must be an easy way.
I have played with gdt.setDisplayValue without success.
Any help is upvoted
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wednesday
Formatting GlideDateTime to dd-MM-yyyy (Scoped Applications)
If you’re working in a scoped application and need to format a date into dd-MM-yyyy, you can use GlideDateTime and split the value accordingly.
🔹 Important Note:
To manipulate the date, always use .getValue() before splitting.
💡 Example 1: Using GlideDateTime
💡 Example 2: Using GlideDate
var gd = new GlideDate().getValue();
If you find my solution helpful then hit the like button.
