# calculating in weeks

New Here ,
Nov 28, 2019 Nov 28, 2019

Copied

if I need to calculate the difference between two dates in weeks and days.

how do I do please ?

I have 3 feilds

the first "DG", the second "date", the third "age

I can make the diffrenece in weeks or days but not both

event.value = 0;var strStart = this.getField("dob").value;var strEnd = this.getField("date").value;if(strStart.length & strEnd.length) {var Start1 = util.scand("dd/mm/yyyy",strStart);var End1 = util.scand("dd/mm/yyyy",strEnd);var diff = End1.getTime() - Start1.getTime();var oneDay = 7 * 24 * 60 * 60 * 1000;var days = Math.floor(diff/oneDay);event.value = days;}

TOPICS
Acrobat SDK and JavaScript, Create PDFs, Edit and convert PDFs, How to, PDF forms

Views

176

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
11 Replies 11
Most Valuable Participant ,
Nov 28, 2019 Nov 28, 2019

Copied

You have to decide exactly how you want to calculate "difference in weeks", there are different ways. How would you do it on paper? For example, Monday 1 to Monday 8. One week or two? Friday 5 to Thursday 11. One week or two? 10 am on Monday 1 to 9 am on Monday 8. One week or two?

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Nov 28, 2019 Nov 28, 2019

Copied

nombre of weeks and days, this calculating isfor pregnancy

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Nov 28, 2019 Nov 28, 2019

Copied

one week or two

and thank you anyway

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
Nov 29, 2019 Nov 29, 2019

Copied

Coders can't work with "one week or two". Code cannot be written until the rules are precisely known, even if that is stricter than people need.  (Also, such a calculation has very serious legal implications, and should not be left up to coders to pick something at random!!)

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Nov 29, 2019 Nov 29, 2019

Copied

It is to calculate gestationnal age

supposing the conception date is 02/11/2019 so the pregnancy age is to 4 weeks

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 29, 2019 Nov 29, 2019

Copied

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Nov 29, 2019 Nov 29, 2019

Copied

It didn't work

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Nov 29, 2019 Nov 29, 2019

Copied

what i need is to calculate the array between tw dates in weeks and days

so that i can know the gestational age the day thar my patient has made her examination

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
Nov 29, 2019 Nov 29, 2019

Copied

I understand your need, but you do not seem to understand our need for you to be mathematically precise. Accountants define these things in great details, and to be it seems medical people need to be just as careful. It seems as if day of week is not important, and you can calculate a number of weeks as a number with decimal places. For example, 8 x 24 hour periods would be approx 1.14 weeks. What is your rule for rounding? For example what would 13 days be counted as: 2 weeks or 1 week?

This is VERY SERIOUS STUFF, as I am sure you know the difference between reporting 24 weeks and 25 weeks could lead to prison in some countries. Coders need to protect themselves (and others) from the consequences of guessing wrong how to code.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Nov 29, 2019 Nov 29, 2019

Copied

gestational age = number of weeks (week = 7 days) + days

exemple : conception date is 15/10/2019 that means gestationnal age is 6 weeks + 3 days   today

and  5 weeks + 1 day   the 20/11/2019

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
Nov 29, 2019 Nov 29, 2019

Copied

LATEST

Thank you for clarifying. This code (a model, not a solution) should give you the ideas you need to get the answer you  want:

// Let's suppose the calculation is for 23 days, in total days

total_days=23
// Calculate exact_weeks, the exact number of weeks (including decimal places)
exact_weeks = total_days / 7 ;

// Round this down to a whole number of weeks in whole_weeks
whole_weeks = Math.floor(exact_weeks) ;

// To calculate the days over, first work out how many days in these whole weeks (whole_weeks_as_days)
whole_weeks_as_days = whole_weeks * 7 ;

// Now work out days_over, the extra days in the current week
days_over = total_days - whole_weeks_as_days ;

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more