Identifying months by name between two dates

Hi!
I have two fields for a study period with a start and end date. I was hoping to use this information to help auto-populate the label of future questions when I need to ask about the number of visits at a health facility for each month within the study period. I was hoping to use a calculation that could pull the name of each month within the two dates (start and end) to show something like this in the label for another field: Number of visits at health facility in ${month1}

Would I need to create another field that is hidden to create month1 from the two dates? I am struggling with understanding how to make this calculation.

Thanks for any help!

You can find some date function in the following link:

format-date(date, '%b')

Is there a maximum number of months the study period can be?
Can the study period stretch across 2 different years?

Have a look at this and see if you can adapt it to your needs. It takes in a start and end date, and then uses these to calculate the number of months in between, and then uses this to populate a repeat group for each month, labelled with their corresponding month name ("Jan", "Feb", ...). It wasn't quite clear from your description whether these needed to be whole months or not - depending on the specific start and end day in each month - so you might need to add 1 to the total months as appropriate.

It should accommodate spans of multiple years.

months.xlsx (9.3 KB)

(adapted from Calculate age in years, months and/or days ... :wink: )

1 Like

@sknudson, does the study period always start on the 1st of a month? If not, will it be confusing if the a "month" runs October 18 - November 17 and is labelled as "October" even though half the dates fall in November?

@Xiphware, I was looking at this last night and referencing that very post of yours :slight_smile:. Is it possible to label with month name and the year? Useful if a long running study might have 2 Aprils.

As requested... :wink:

months_and_year.xlsx (9.4 KB)

1 Like

It is usually going to be a 12 month study period, but we want to make sure that disruptions like floods, COVID pandemic, etc. that might affect the health facility are accounted for, so they get to choose their start and end date.

This is super helpful! I hadn't thought about how we are collecting information for the month if the study period starts midway through - I'll have to ask our study lead, but I imagine we do want them to start at the beginning of each month. Thank you for your help!

Np. Depending on precisely how you end up defining your start and/or end 'month' you may need to tweak the form calculations a little; eg override the start day to always be 1, override the end day to be the last day in the month [the form as provided already has what you need to calculate this number]. But it should accommodate.

1 Like

absolutely genius. thanks for sharing.