### 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?

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