5 Replies Latest reply on Nov 3, 2011 12:15 AM by KimmSun

# Error calculating weeks

### Title

Error calculating weeks & days elapsed

### Post

I am calculating the number of weeks & days a woman is pregnant (aka WGA, weeks gestational age), by calculating weeks & days elapsed between start of pregnancy and the date of her prenatal appointment.  Start of pregnancy is calculated from her estimated due date (EDDforWGA, a calculated field, date result) minus 280 (length of the average pregnancy in days).  The Pregnancies layout contains a Prenatals portal:

Prenatals::WGA = Int ( Dateofprenatal - ( Pregnancies::EDDforWGA - 280 ) / 7 ) & "w" & Mod (  Dateofprenatal - ( Pregnancies::EDDforWGA - 280 ); 7 ) & "d"

The result of the calculation was working, but I'm not sure what I did, as it is now giving a result that is obviously wrong, showing a number hundreds of thousands of weeks pregnant.  I did a test to try to find where it is messed up, and I believe it is calculating the first day of pregnancy as being the Year 0001.  Could someone tell me what is wrong with my calculation?

• ###### 1. Re: Error calculating weeks & days elapsed

There seems to be an error here:  Int ( Dateofprenatal - ( Pregnancies::EDDforWGA - 280 ) / 7 )

looks like it should be: Int ( ( Dateofprenatal - Pregnancies::EDDforWGA - 280 ) / 7 )

when I compare it to the Mod function you use later in the same expression.

Also, check the value in Dateofprenatal. Make sure this field is of type date or a calculation field with Date selected as its return type. You can simplify your expression a bit if you want to:

Let ( start = Dateofprenatal - Pregnancies::EDDforWGA - 280 ; Div ( start ; 7 ) & "w " & Mod ( start ; 7 ) &"d" )

• ###### 2. Re: Error calculating weeks & days elapsed

Thanks, working now.  Thanks Phil. Thinking I need a class.

• ###### 3. Re: Error calculating weeks & days elapsed

Hi Anita:

May I get some assist, too?  I am trying to understand which are your fields:

what is the Pregnancies field?  Do you also have a field for EDDforWGA?

Thanks

Kimm

• ###### 4. Re: Error calculating weeks & days elapsed

EDDforWGA is a field, and Pregnancies is the table it comes from. Hence, Pregnancies:EDDforWGA.

• ###### 5. Re: Error calculating weeks & days elapsed

Hi Anita:

I'm read through your instructions, but I don't why it didn't work for me.  This is my formula:

((TODAY - LMP) / (60 * 60 * 24)) / 7  ,  TODAY being the instructions for putting in the present day, and LMP being date field that I've entered.  It actually works, except it doesn't give me week and day, only the number representing the week, rounding up - 35 weeks 5 days will give me 36.  I can use decimal, but it's not what I want achieve.

I am interested in getting a wk and day format such as 23w2d.  I am willing to separate it into 2 fields, one for Week and Day.