Skip to page contentSkip to chat
ServiceNow support
    • Community
      Ask questions, give advice, and connect with fellow ServiceNow professionals.
      Developer
      Build, test, and deploy applications
      Documentation
      Find detailed information about ServiceNow products, apps, features, and releases.
      Impact
      Accelerate ROI and amplify your expertise.
      Learning
      Build skills with instructor-led and online training.
      Partner
      Grow your business with promotions, news, and marketing tools
      ServiceNow
      Learn about ServiceNow products & solutions.
      Store
      Download certified apps and integrations that complement ServiceNow.
      Support
      Manage your instances, access self-help, and get technical support.
gs.dateDiff() (Global GlideSystem) returns invalid results - Support and Troubleshooting
  • >
  • Knowledge Base
  • >
  • Support and Troubleshooting (Knowledge Base)
  • >
  • gs.dateDiff() (Global GlideSystem) returns invalid results
KB0594663

gs.dateDiff() (Global GlideSystem) returns invalid results


32329 Views Last updated : Nov 21, 2024 public Copy Permalink English (Original)
  • English (Original)
  • Japanese
KB Summary by Now Assist

Issue

Problems can occur when using gs.dateDiff() with GlideDateTime objects.

Procedure

The dateDiff() method expects parameters in the user/system format, and the GlideDateTime constructors expect parameters in the internal format (yyyy-MM-dd HH:mm:ss) and in the UTC time zone.

Using the dateDiff() method with other formats may return invalid results.

Instead, of using gs.dateDiff() use the GlideDateTime.subtract() method.

Correct way

var gdt1 = GlideDateTime('2015-07-24 18:58:00');
var gdt2 = GlideDateTime('2015-07-24 19:01:00');
var duration2 = GlideDateTime.subtract(gdt1, gdt2);

Incorrect way

var gdt1 = GlideDateTime('2015-07-24 18:58:00');
var gdt2 = GlideDateTime('2015-07-24 19:01:00');
var duration1 = gs.dateDiff(gdt1, gdt2, false);

If you must use gs.dateDiff(), do this

var gdt1 = GlideDateTime('2015-07-24 18:58:00');
var gdt2 = GlideDateTime('2015-07-24 19:01:00');
var duration1 = gs.dateDiff(gdt1.getDisplayValue(), gdt2.getDisplayValue(), false);

The gs.dateDiff() method is not available in scoped applications.

Related Links

If the issue is with subtract(GlideDateTime start,GlideDateTime end) method, then refer to KB0824807


The world works with ServiceNow.

Sign in for more! There's more content available only to authenticated users Sign in for more!
Did this KB article help you?
Did this KB article help you?

How would you rate your Now Support digital experience?

*

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

What can we improve? Please select all that apply.

What are we doing well? Please select all that apply.

Tell us more

*

Do you expect a response from this feedback?

  • Terms and conditions
  • Privacy statement
  • GDPR
  • Cookie policy
  • © 2025 ServiceNow. All rights reserved.