Auto Update Field based on Date

I have created a custom field which is “select” type in sales order, and it has 4 options “Overdue”, “This Week”, “Next Week”, “Upcoming”.
I want this field to auto update based on the difference between delivery date and today. I tried doing it through client script but am not very good at that.

Could anyone please share the script for the same.

Would really appreciate the effort.
Thank you

I have written the following code in the client script, but am not able to make it work properly.
Also, the effect only happens in new orders made, but I want the field to be updated for all old records.

Could anyone guide me with the proper script
frappe.ui.form.on(‘Sales Order’, {
refresh(frm) {
// your code here
//cur_frm.cscript.custom_delivery_date = function(doc, cdt, cd){
//cur_frm.set_value(“submit_date”, frappe.datetime.add_days(doc.delivery_date, +2));
if(frm.doc.delivery_date < get_today(+5)) {
frm.set_value(“dispatch_schedule”,“This Week”);
//msgprint(‘You can not select past date in From Date’);
else if(frm.doc.delivery_date > get_today()) {
frm.set_value(“dispatch_schedule”,“Next Week”);