Custom 'Created date' field capturing incorrect values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2025 11:08 PM
Hi All,
I have a requirement to capture the 'Created' i.e sys_created_on values on a new field that captures only the created date and not the time stamp for reporting purpose, same with the updated and closed fields
So i have created a new Date field 'Created date' and configured a business rule to update this field value.
But this newly created date field is not capturing correct values, there is a difference of a day (lag) between created dates in custom field and OOB field.
Can anyone suggest. Below are the details.
Business Rule
Type - Before Insert
Script-
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2025 02:12 AM
if the custom fields are of date type then it should work fine.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2025 11:36 PM - edited ‎04-07-2025 11:38 PM
Hello @sanvi ,
This is expected behavior in ServiceNow and your code is correct.
Please note that ServiceNow internally uses the UTC time zone for date and time fields.
You seem to be in a time zone that is at least 10 hours ahead of UTC.
For the first record the "Created" date/time is still in late evening of March 26 UTC, but in the UI you see it as March 27 because of your time zone setting.
For the first record the "Created" date/time is in the early morning of March 13 UTC, which is also March 13 in your time zone.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2025 11:55 PM
Hi @Robert H ,
Yes my timezone is Aust/Melbourne time zone and the issue is not happening for all the tickets its only for few created early morning.
How to overcome this issue?? is there any solution? as this is impacting on the reporting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2025 12:01 AM - edited ‎04-08-2025 12:24 AM
Hello @sanvi ,
This is not an issue. It's a very normal thing because the world is divided up into time zones, and in some time zones it's already one day later as in other time zones.
So unless your company/client is only operating in Australia and has no business or offices in other parts of the world you should keep things as they are.
Else you would have to rename your custom fields to something "Created (Australia time)" to avoid misinterpretation and then in your Business Rule convert the internal date/timestamp (which is in UTC) into Australia time by adding the difference between Australia and UTC to it:
var created = current.sys_created_on;
var date = new GlideDateTime(created);
date.setTimeZone('Australia/Melbourne');
date.add(date.getTZOffset());
current.u_created = date.getDate();
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2025 02:06 AM
Hi @Robert H ,
Thanks for your response. I have modified one of the script as u mentioned. Will get to know exact results in the morning.
Will get back to you.