Skip to main content
waelk38411626
Known Participant
Nov 28, 2019 9:43 PM UTC
Question

calculating in weeks

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;}

This topic is closed to new replies. Start a new post to keep the conversation going.

11 replies

Legend
Nov 29, 2019 10:09 AM UTC

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 ;

Translate
Bernd Alheit
Community Expert
Community Expert
Nov 29, 2019 9:26 AM UTC
waelk38411626
Known Participant
Nov 29, 2019 9:28 AM UTC

It didn't work

Translate
waelk38411626
Known Participant
Nov 29, 2019 9:30 AM UTC

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 

Translate
Legend
Nov 29, 2019 9:13 AM UTC

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

Translate
waelk38411626
Known Participant
Nov 29, 2019 9:27 AM UTC

It is to calculate gestationnal age 

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

Translate
Legend
Nov 28, 2019 10:42 PM UTC

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? 

Translate
waelk38411626
Known Participant
Nov 29, 2019 6:13 AM UTC

nombre of weeks and days, this calculating isfor pregnancy

Translate