Change Date Format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hello,
I am getting date in string as 01-Feb-99. How can I convert this date into dd-mm-yyyy?
Please guide.
Thanks in advance !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago - last edited an hour ago
Hey Drishti,
You can use the GlideDate.getByFormat() function for this. A more extensive use-case example can be found here.
Regards
Fabian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @Drishti
// Your input date string
var dateStr = "01-Feb-99";
// Create a GlideDateTime object
var gdt = new GlideDateTime();
gdt.setDisplayValue(dateStr);
// Get the date in yyyy-MM-dd format first
var date = gdt.getDate();
// Parse and reformat to dd-mm-yyyy
var parts = date.toString().split("-");
var formattedDate = parts[2] + "-" + parts[1] + "-" + parts[0];
gs.info("Formatted Date: " + formattedDate); // Output: 01-02-1999if for server side than you can use this, this code snippet works
hope this helps, if helped please mark helpful and Accept as solution 🙂
Warm Regards
Sumit
Technical Consultant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago - last edited an hour ago
Hey,
Using GlideDate.getByFormat() as from this example is much better in this case - especially when using the GlideDate object already.
Regards
Fabian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
try this in background Script
var dateString = '01-Feb-99';
var gd = new GlideDate();
// Step 1: Parse input string using display format
gd.setDisplayValue(dateString, 'dd-MMM-yy'); // Input format pattern
// Step 2: Output in desired dd-mm-yyyy format
var formattedDate = gd.getByFormat('dd-MM-yyyy');
gs.info('Formatted: ' + formattedDate); // Output: 01-02-1999
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
