Copy link to clipboard
Copied
I am working on a form where I want to subtract my date field from a "week" field to create a new date. I am creating a timeline for my workbook. So the equation I want is
(Date of the Event)-(Week Form)*7=Date
I can get to formula to pop out the number of days but I cannot get it to format into a date field.
I will need to do a similar formula but with time where I subtract hours from a "start time" so the formula will be (Start Time)-(Hours)=Time
Thank you in advance.
Copy link to clipboard
Copied
Hi, I am looking for a similar solution using two fields, one with todays date which updates every day, and the other with a pervious date (fixed point in time) to calculate the number of days between the two dates and then divide by 7 to get a week count. Each day you open up the page it updates the week count . You would think that it was simple logic, but not so. After having a go with my own scripts I have had to resort to reserarching this process, and modified multiple scrpits to no avail. I have a script in the new date field to calcualte that so all good as I have this in its own field. What I am seeking to do is to take two date fields from each other and get the the total number of days and divide by 7 to get a week count. ("Today" - "Date1A)/7 = total number of weeks in the period.
I am still working on it, and if a find a solution I will post.
Copy link to clipboard
Copied
Try this, it will show a result with 1 decimal:
var date1 = this.getField("Today").valueAsString;
var date2 = this.getField("Date1A").valueAsString;
if(date1&&date2){
var dateT = util.scand("mmmm d, yyyy", date1);
var dateF = util.scand("mmmm d, yyyy", date2);
var diff = (dateT.getTime() - dateF.getTime())/1000;
var days = (((diff / 60) / 60) / 24)/7;
event.value = util.printf("%0.1f", days);}
else
event.value = "";
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi Nesa,
Thankyopu for your help with this. At first I was getting a null value from thre Date 2 field, but I sorted out by fixing the date format and this seemed to resolve that issue. But I am now getting this error: InvalidSetError:Set no possible, Invalid or unknown. Event.value:8: Field EeekCount:Mouse Exit
This is the scirpt so far:
var date1 = this.getField("Today").valueAsString;
var date2 = this.getField("Date4").valueAsString;
if(date1&&date2){
var dateT = util.scand("d-mmm-yy", date1);
var dateF = util.scand("d-mmm-yy", date2);
var diff = (dateT.getTime() - dateF.getTime())/1000;
var days = (((diff / 60) / 60) / 24)/7;
event.value = util.printf("%0.2f", days);}
else
event.value = "";
I am working through this but not getting very far. Any thoughts
Copy link to clipboard
Copied
If you are using script on 'Mouse Exit' then change:
event.value
to
event.target.value
Copy link to clipboard
Copied
Your wonderful.... I hope someone has told you today.
Ima working on another c=scirpt that runs through ifelse statement to pick a dollar value. I am getting a simil;ar error. I will use the same logic to see if it works.