Custom 'Created date' field capturing incorrect values.

sanvi
Tera Expert

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-

 

current.u_created = current.sys_created_on;
   //current.update();
 
Report-
 
sanvi_0-1744092477030.png

Thanks in advance.

11 REPLIES 11

Shivalika
Mega Sage

Hello @sanvi 

 

There is difference in timezone that's why. 

 

Instead of copying it, just use "now Date()" - function from OOB. 

 

Shivalika_0-1744101613839.png

 

Shivalika_1-1744101635468.png

 

OR

 

Shivalika_2-1744101679934.png

 

 

Shivalika_3-1744101690730.png

 

There are other ways also, you can use "GlideDateTIme() and then use "getDate()" method to just extract date from it. 

 

I hope this answers your queries. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

 

 

 

 

 

 

Vasantharajan N
Giga Sage
Giga Sage

@sanvi - This is an expected behavior because of the Date field type is not based on the user timezone. 

 

Say when the user timezone and system timezone matches then you won't experience the difference. when the user time zone and system time zone is different then you will see the difference. 

 

Little more about GlideDate object is explained in the article below,

https://www.servicenow.com/community/developer-forum/glidedate-object-always-returns-utc-as-timezone...


Thanks & Regards,
Vasanth