How to correct and update the date field values

Sandhya23
Tera Guru

Hi All,

I have a requirement where I need to correct the date in the field "start_date".

Currently the field has future date, Say for example - 02/12/2022 10:11:33 (2nd of Dec) which is 8 month from now. However I need to alter the value from 2nd Dec to 12th Feb and update the start_date with new value for all the affected records. How can I achieve this ? Any suggestion would be very helpful. thanks !!

Hi @Sanjiv Meher  Do you have any thoughts on this as I found one of your blog on dates fields.

Regards,
Sandhya

1 ACCEPTED SOLUTION

Sandhya23
Tera Guru

Hi Hitoshi,

Here is what I did to resolve my future date issue.

1. Cleared all the future dated values from start_date.

2. Get the source file with correct data and transform the date values in the system.

3. Created a Business Rule to prevent population of any future date.

 

 

 

View solution in original post

9 REPLIES 9

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Sandhya,

I'll just write a Background script to update the start_date.

Would need more detailed information. What is the logic to convert date? Is it all 02/12/2022 to 12/02/2022?

If the date was entered in error, I'll use Fix script.

 

Following is an sample script that will change all the records that have start_date = '2022-12-02 10:11:33' to '2022-02012 10:11:33'. Need more exact specification on what is required.

var curDate =  '2022-12-02 10:11:33';
var newDate = '2022-02-12 10:11:33';

var gr = new GlideRecord('<table name>');
gr.addActiveQuery();
gr.addQuery('start_date', curDate);
gr.query();
while(gr.next()) {
  gr.startDate = newDate;
  gr.update();
}

Sandhya23
Tera Guru

Hi Hitoshi,

Yeah fix script is what I am thinking of. There are 2 parts in this issue

1. Remediate the existing records with wrong value of start_date.

2. Monitor if start_date field value updates in future dated. If so, amend the field value to correct the data.

So basically its not just about a single record that I need to update. I am looking to convert the start_date field values for all the records (identified as wrong values) in a table. There are values for start_date which is in the future dated and needs to be converted to the dates in the past as I have mentioned in the example above. 

example - 02/12/2022 10:11:33 (2nd of Dec) which is 8 month from now. However I need to alter the value from 2nd Dec to 12th Feb and update the start_date with new value for all the affected records. Basically the day and month in the date field needs to be changed and updated.

Regards,

 

Hi Sandhya,

What is the logic for the new date? Is it always 8 months if the start_date is a future date? Should time also be converted or remain the same.