Period format for custom data entry app

About the WHEN dimension of data value, I saw that in the demo database we have a periodtype table with about predefined records such as Daily, Weekly, Monthly. And also a period table with periodtypeid, startdate and enddate. Since I am using a blank database, my period table is blank. For example say I want to store data value for August 2022. I first need to create a period with periodtypeid for monthly, startdate as 01-08-2022 and end date as 31-08-2022.
Now in the doc example they put the data period value as Aug-22. But in the database there is no reference to period name like this. The primary key is the periodid.

a. In my form period parameter value should I use the periodid or a string value say ‘Aug-22’ to store the period? I saw different example like in the api doc 201401.
b. If I am using a string value, how is this value connected to the period table.

Hi @jetisco4u,

a. To reference a monthly period in the WebAPI, such as for data entry, it should be in the form yyyyMM such as ‘202208’. A full list of WebAPI formats for every period type can be found at Developer Manual - DHIS2 Documentation

b. The backend will parse the period format that you supply, will create that period if it doesn’t yet exist in the database, and will store the datavalue with a reference to the correct periodid primary key.

DHIS2 follows the recommended practice for relational database applications in that the internal numeric database ids that are used for primary/foreign key relationships in the database are not exposed to the user through the WebAPI.

1 Like

@Jim_Grace thanks for the clarification. The point b is what I really struggle to figure out. It make sense. but I am curious, in my country we use the date format ddMMyyyy. I am wondering if I store data in this format yyyyMMdd can I get to show it in a format I want for visual tools? In my current app I convert the format before sending to the backend. I know I can set the date format in systemsetting. I just wanted to know if it will be sufficient.

@jetisco4u No problem. I’ve never actually used the date format in the system settings, but I believe this will do exactly what you want.

The period formats such as 202208 for the month of August 2022 are used in the WebAPI but not in the database. In the database, intervals are stored including their start date and end date, in whatever internal format the database uses for storing dates.