• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

calculating in weeks

Community Beginner ,
Nov 28, 2019 Nov 28, 2019

Copy link to clipboard

Copied

Help please 

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

please help me

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

Views

427

Translate

Translate

Report

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

Copy link to clipboard

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? 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

nombre of weeks and days, this calculating isfor pregnancy

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

one week or two 

and thank you anyway

Votes

Translate

Translate

Report

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

Copy link to clipboard

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!!) 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

It is to calculate gestationnal age 

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

It didn't work

Votes

Translate

Translate

Report

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

Copy link to clipboard

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 

Votes

Translate

Translate

Report

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

Copy link to clipboard

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

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 

Votes

Translate

Translate

Report

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

Copy link to clipboard

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 ;

Votes

Translate

Translate

Report

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