- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 04:29 AM
Hello how are you?
I need to calculate the difference between two dates, but it's calculating wrong,
because of the date formatting Example: I need to convert "2021-12-06 08:00:00"
to "06-12-2021 08:00:00" to see if it calculates right, this is the script I'm using:
Business Rule:
var gdt1 = new GlideDateTime(current.getDisplayValue('u_data_inicio_lb2'));
var gdt2 = new GlideDateTime(current.getDisplayValue('u_data_termino_lb2'));
var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2
current.setValue("u_duracao_lb2",dur);
Gracias!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 11:33 AM
Hi,
You will need to change the format of date and test it. I tried this script and it returned me 32 days. I have hardcoded the dates. Please change it.
var gdt = new GlideDateTime("01/11/2021 08:00:00");
var myDate = gdt.getDate();
var gt = gdt.getTime();
var fd = myDate.getByFormat('dd-MM-yyy') + gt.getByFormat(' HH:mm:ss')
gs.info(fd); //
var gdts = new GlideDateTime("03/12/2021 08:00:00");
var myDates = gdts.getDate();
var gts = gdts.getTime();
var fds = myDates.getByFormat('dd-MM-yyy') + gts.getByFormat(' HH:mm:ss')
gs.info(fds);
var time1 = new GlideDateTime(fd);
var time2 = new GlideDateTime(fds);
var dur = GlideDateTime.subtract(time1, time2);
gs.info(dur.getDisplayValue());
Output showed as -
*** Script: 11-01-2021 08:00:00
*** Script: 12-03-2021 08:00:00
*** Script: 32 Days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 07:09 AM
in this data format the result is wrong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 07:07 AM
The format my system is dd-mm-yyyy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 07:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 11:33 AM
Hi,
You will need to change the format of date and test it. I tried this script and it returned me 32 days. I have hardcoded the dates. Please change it.
var gdt = new GlideDateTime("01/11/2021 08:00:00");
var myDate = gdt.getDate();
var gt = gdt.getTime();
var fd = myDate.getByFormat('dd-MM-yyy') + gt.getByFormat(' HH:mm:ss')
gs.info(fd); //
var gdts = new GlideDateTime("03/12/2021 08:00:00");
var myDates = gdts.getDate();
var gts = gdts.getTime();
var fds = myDates.getByFormat('dd-MM-yyy') + gts.getByFormat(' HH:mm:ss')
gs.info(fds);
var time1 = new GlideDateTime(fd);
var time2 = new GlideDateTime(fds);
var dur = GlideDateTime.subtract(time1, time2);
gs.info(dur.getDisplayValue());
Output showed as -
*** Script: 11-01-2021 08:00:00
*** Script: 12-03-2021 08:00:00
*** Script: 32 Days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2022 04:03 AM
Hi,
Did you get a chance to check this? Is this working for you ?