How to modify date format from mm/dd/yyyy to yyyy-mm-dd in onbefore transform script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2020 11:05 AM
Hi,
Can i know how we can modify the date format from mm/dd/yyyy to yyyy-mm-dd in onbefore transform script. The target table has date field as a textbox.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2024 04:06 AM
What do you mean by incoming date here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2025 05:37 PM
I've found the getByFormat is unreliable, the best way to sort out date problems in your environment once and for all by creating your own date libraries to manage the transitions between local and system dates and format switching etc. I put this script together to catch the differences we were seeing in Australia early in the morning when the GMT date was different to our local date.
var myDate = new GlideDateTime();
gs.print(myDate);
gs.print(myDate.getDisplayValue());
gs.print(myDate.getDate() + '\n\n');
var fixDate = '2025-08-22';
var theDate = new GlideDateTime(fixDate);
gs.print(theDate);
gs.print(theDate.getDisplayValue());
gs.print(theDate.getDate() + '\n\n');
// how to make a GlideDateTime field "date-only" and have it work with date-only processing local or system time
var ds1 = myDate.getDisplayValue().split(' ');
var ds2 = ds1[0].split('-');
var newDate = new GlideDateTime(ds2[2] + '-' + ds2[1] + '-' + ds2[0]);
gs.print(newDate);
gs.print(newDate.getDisplayValue());
gs.print(newDate.getDate() + '\n\n');
*** Script: 2025-08-21 23:44:56
*** Script: 22-08-2025 09:44:56
*** Script: 2025-08-21
*** Script: 2025-08-22 00:00:00
*** Script: 22-08-2025 10:00:00
*** Script: 2025-08-22
*** Script: 2025-08-22 00:00:00
*** Script: 22-08-2025 10:00:00
*** Script: 2025-08-22
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2025 05:55 PM
I'll add this to cover the LocalDate function too.
var myDate = new GlideDateTime();
gs.print(myDate);
gs.print(myDate.getDisplayValue());
gs.print(myDate.getDate() + ' —(SYSTEM DATE)');
gs.print(myDate.getLocalDate() + ' —(LOCAL DATE)\n\n');
*** Script: 2025-08-21 23:44:56
*** Script: 22-08-2025 09:44:56
*** Script: 2025-08-21 ---(SYSTEM DATE) *** Script: 2025-08-22 ---(LOCAL DATE)
