Hello,
I have some problem calculating weeks. So, it would like last menstrual period - today (or specific date) then will get the number of weeks.
as of now, I only found difference-in-months, when I try this as "difference-in-weeks(${pregnant_date},${specific_date}), and I will only get an error from the front-end of the app, “Error loading form. Please try again or check with an administrator.”
Thanks for helping me.
Unfortunately, we do not have a handy function for calculating difference in weeks like difference-in-months. However, I think the default pregnancy
form has a good example of doing the exact calculation you are looking for!
The relevant part is as follows (where lmp_date_8601
holds the date value of the recorded last menstrual period):
type |
name |
calculation |
calculate |
days_since_lmp |
floor(decimal-date-time(today())) - decimal-date-time(…/lmp_date_8601) |
calculate |
weeks_since_lmp |
round(…/days_since_lmp div 7, 2) |
calculate |
weeks_since_lmp_rounded |
floor(…/days_since_lmp div 7) |
Basically, the decimal-date-time
function makes it easy to calculate the difference in days between two dates. Then just divide by 7 to get the weeks value.