- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2020 03:44 AM
Can anyone help me displaying the getDateTime() value DDMMYYHHMMSS format
Thanks,
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2020 03:50 AM
Hi
To change the format, you first need to set up GlideDateTime using your current format
var date = '10 Jul 2018 12:30:00';
var simpleDateFormat = 'dd MMMM yyyy HH:mm:ss'; // Simple Date Time format
var gdt = new GlideDateTime();
gdt.setDisplayValue(date,simpleDateFormat); //Set time using current TZ
gs.addInfoMessage(gdt.getDisplayValue()); // Output time in current TZ
2018-07-10 12:30:00 PM |
Once your GlideDateTime object has the correct time, you can manipulate it as you need.
gdt.addDays(7);
gs.addInfoMessage(gdt.getDisplayValue());
2018-07-17 12:30:00 PM |
And back again to your original format, with the added 7 days
var gd = gdt.getLocalDate();
var gt = gdt.getLocalTime();
gs.addInfoMessage(gd.getByFormat('dd MMM yyyy') + gt.getByFormat(' HH:mm:ss'));
17 Jul 2018 12:30:00 |
refer this artical for more:
https://community.servicenow.com/community?id=community_blog&sys_id=bc0e6a2ddbd0dbc01dcaf3231f961931
If it help mark helpful or correct
Thanks and regards
Anil

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2020 03:50 AM
Hi
To change the format, you first need to set up GlideDateTime using your current format
var date = '10 Jul 2018 12:30:00';
var simpleDateFormat = 'dd MMMM yyyy HH:mm:ss'; // Simple Date Time format
var gdt = new GlideDateTime();
gdt.setDisplayValue(date,simpleDateFormat); //Set time using current TZ
gs.addInfoMessage(gdt.getDisplayValue()); // Output time in current TZ
2018-07-10 12:30:00 PM |
Once your GlideDateTime object has the correct time, you can manipulate it as you need.
gdt.addDays(7);
gs.addInfoMessage(gdt.getDisplayValue());
2018-07-17 12:30:00 PM |
And back again to your original format, with the added 7 days
var gd = gdt.getLocalDate();
var gt = gdt.getLocalTime();
gs.addInfoMessage(gd.getByFormat('dd MMM yyyy') + gt.getByFormat(' HH:mm:ss'));
17 Jul 2018 12:30:00 |
refer this artical for more:
https://community.servicenow.com/community?id=community_blog&sys_id=bc0e6a2ddbd0dbc01dcaf3231f961931
If it help mark helpful or correct
Thanks and regards
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2020 03:59 AM
Thanks for reply.colons in this format ?
will it work If i give like this getByFormat('HHMMSS')
getByFormat(' HH:mm:ss'));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2020 10:05 PM
Hi,
Try this code in Background script:
var gdt = new GlideDateTime();
var gd = gdt.getLocalDate();
var gt = gdt.getLocalTime();
gs.print(gd.getByFormat('dd MM yy') + gt.getByFormat(' HH:mm:ss'));
output:
Please mark as Correct and Helpful, if your issue is resolved
Regards,
Subhojit Das

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2020 03:52 AM