Skip to main content
Participating Frequently
January 30, 2024
Answered

Calculating Due Date in hours

  • January 30, 2024
  • 1 reply
  • 1202 views

Is there a way to calculate a due date (60 hours) based on another date/time entered?

 

The specific scenario is I have a cooler that is packed with ice on 30JAN2024 at 1300. It expires in 60 hours. I want that date/time to automatically be entered.

This topic has been closed for replies.
Correct answer try67

The date fields are formatted as dd-mmm-yyyy; the time fields are formatted as HH:MM


OK, then you can use this code as the custom calculation script of "Expiration Date":

 

var packedDateString = this.getField("Packed Date").valueAsString;
var packedTimeString = this.getField("Packed Time").valueAsString;

if (packedDateString=="" || packedTimeString=="") {
	event.value = "";
	this.getField("Expiration Time").value = "";
} else {
	var expDate = util.scand("dd-mm-yyyy HH:MM", packedDateString + " " + packedTimeString);
	expDate.setTime(expDate.getTime()+(60*3600000));
	event.value = util.printd("dd-mm-yyyy", expDate);
	this.getField("Expiration Time").value = util.printd("HH:MM", expDate);
}

1 reply

try67
Community Expert
Community Expert
January 30, 2024

Yes, this is possible. Do you have a single field for the packing time, or is it one field for the date, and another for the time? What is the format of this field/s?

try67
Community Expert
Community Expert
January 30, 2024

And what are their names?

Participating Frequently
January 30, 2024

Here is a screenshot of the section.