Hi All

basha shaik
Tera Contributor

Hi All,

 

I Have two Date Fields

1. start date 2. end date

 I have another Field count Days

 

 How to Decrease Days as per system date.

 

bashashaik_0-1696220382158.png

 

Thanks

 

4 REPLIES 4

Danish Bhairag2
Tera Sage
Tera Sage

Hi @basha shaik ,

 

Assuming all these fields shown in your image are from custom table n as they are Read only. U can write a schedule job which runs daily calculating the days left by subtracting start n end date n updating the count date field for all records on daily basis.

 

Please mark my answer helpful & accepted if it helps you resolve your query.

 

Thanks,

Danish

can you  Please provide code

Hi @basha shaik ,

 

U can refer below code, please make necessary changes wherever required in terms of field names.

var gr = new GlideRecord('change_request');// please use proper table name in which ur field are present
gr.addEncodedQuery('start_dateISNOTEMPTY^end_dateISNOTEMPTY');//script should only execute for records where both fields are filled
gr.query();
while (gr.next()) {
    var startDate = new GlideDateTime(gr.start_date);//use proper backend name of the start date field
    var endDate = new GlideDateTime(gr.end_date);//use proper backend name of the end date field
    var duration = GlideDateTime.subtract(endDate, startDate);
    var days = duration.getDayPart();// this will give u the number of days left
	gr.count_date = days;
	gr.update();
}

 

Please mark my answer helpful & accepted if it helps you resolve your query.

 

Thanks,

Danish

Hi @basha shaik ,

 

If the solution did work for you can make it accepted as well & close the thread so for others to benefit from it please.

 

Thanks,

Danish