It is a common requirement to allow the entry of partial dates, when the data entry user does not know the exact date. For example, a question to record the date on which a patient last smoked may be set up to allow the entry of a year and month only, or even a year only.
There are several Arezzo functions which automatically handle partial dates:
A partial date value may have its day missing, or it may have its day and month missing. For a date question, the partial date formats allowed are:
mm/yyyy or m/yyyy
yyyy/mm or yyyy/m
yyyy
A time (hh:mm or hh:mm:ss) may not be included with a partial date.
Click here for further information on how to switch on partial date handling, and how to create partial date questions.
The following Arezzo date functions are especially affected by partial dates:
For the comparisons isbefore and isafter between date questions D1 and D2, where partial dates are allowed, comparisons will only be made between the time units that appear in both dates. For example:
D1 |
D2 |
Comparison |
dd/mm/yyyy |
dd/mm/yyyy |
Use existing full date comparison |
dd/mm/yyyy |
mm/yyyy |
Compare yyyy values: if equal, compare mm values |
dd/mm/yyyy |
yyyy |
Compare yyyy values only |
mm/yyyy |
dd/mm/yyyy |
Compare yyyy values: if equal, compare mm values |
mm/yyyy |
mm/yyyy |
Compare yyyy values: if equal, compare mm values |
mm/yyyy |
yyyy |
Compare yyyy values only |
yyyy |
dd/mm/yyyy |
Compare yyyy values only |
yyyy |
mm/yyyy |
Compare yyyy values only |
yyyy |
yyyy |
Compare yyyy values only |
For consistency with isbefore and isafter, a partial date is equal to a full date if the given parts match, i.e. if
D1 = 15/3/2001
D2 = 3/2001
then the condition
D1 = D2
will be true. Study designers must bear this in mind when dealing with partial dates. For example, assume D1 and D2 are dates with format of dd/mm/yyyy, mm/yyyy or yyyy:
D1 |
D2 |
D1=D2 |
D1 isbefore D2 |
D1 isafter D2 |
15/3/2001 |
3/2001 |
True |
False |
False |
15/3/2001 |
2001 |
True |
False |
False |
15/3/2001 |
4/2001 |
False |
True |
False |
15/3/2001 |
2004 |
False |
True |
False |
15/3/2001 |
2000 |
False |
False |
True |
8/2001 |
31/8/2001 |
True |
False |
False |
8/2001 |
8/2001 |
True |
False |
False |
8/2001 |
5/2001 |
False |
False |
True |
8/2001 |
2001 |
True |
False |
False |
8/2001 |
2002 |
False |
True |
False |
2003 |
2003 |
True |
False |
False |
2003 |
7/2003 |
True |
False |
False |
2003 |
11/7/2003 |
True |
False |
False |
2003 |
2004 |
False |
True |
False |
2003 |
10/1999 |
False |
False |
True |
2003 |
1/1/2005 |
False |
True |
False |
The time_diff function returns elapsed time, in whole time units. (This is the correct function for calculating a person’s age). For dates D1 and D2, the calculation can only be done for the following time units:
D1 |
D2 |
Time Units |
dd/mm/yyyy |
dd/mm/yyyy |
years, months, weeks, days |
dd/mm/yyyy |
mm/yyyy |
years |
dd/mm/yyyy |
yyyy |
- |
mm/yyyy |
dd/mm/yyyy |
years |
mm/yyyy |
mm/yyyy |
years, months |
mm/yyyy |
yyyy |
- |
yyyy |
dd/mm/yyyy |
- |
yyyy |
mm/yyyy |
- |
yyyy |
yyyy |
years |
To be able to calculate an age from a partial DOB, use the full_date function as described in this topic.
The date_diff function returns an arithmetical calendar difference (without considering parts of units). For dates D1 and D2, the calculation can only be done for the following time units:
D1 |
D2 |
Time Units |
dd/mm/yyyy |
dd/mm/yyyy |
years, months, weeks, days |
dd/mm/yyyy |
mm/yyyy |
years, months |
dd/mm/yyyy |
yyyy |
years |
mm/yyyy |
dd/mm/yyyy |
years, months |
mm/yyyy |
mm/yyyy |
years, months |
mm/yyyy |
yyyy |
years |
yyyy |
dd/mm/yyyy |
years |
yyyy |
mm/yyyy |
years |
yyyy |
yyyy |
years |
Date additions and subtractions involve expressions such as the following:
DOB + 3 months
StartDate - 2 days
Additions and subtractions can only be done if the date contains the specified time unit, i.e.
Date Format |
Acceptable Time Units |
dd/mm/yyyy |
years, months, weeks, days |
mm/yyyy |
years, months |
yyyy |
years |
The result will be a full or partial date of the same sort as the original. In the following examples D is a partial date question with format dd/mm/yyyy:
D |
Arezzo Expression |
Result |
20/3/2006 |
D + 5 days |
25/3/2006 |
20/3/2006 |
D - 1 week |
13/3/2006 |
3/2006 |
D + 8 days |
- |
3/2006 |
D - 2 weeks |
- |
3/2006 |
D - 2 months |
1/2006 |
3/2006 |
D + 3 years |
3/2009 |
2006 |
D - 2 months |
- |
2006 |
D - 10 years |
1996 |
To specify an explicit partial date in an Arezzo expression, use the date function with 0 for a missing month or day. For example:
Arezzo Expression |
Meaning |
date( 2005, 12, 25 ) |
25th December 2005 |
date( 1962, 10, 0 ) |
October 1962 |
date( 1945, 0, 0 ) |
1945 |
If a time is specified, the day and month must not be 0.
The function is_partial_date returns true or false depending on whether the given date is partial (regardless of a question's format). A partial date format may optionally be given. Note that the first argument must always be a date question (not a text question), or a date expression.
is_partial_date( Date ) - True if the given date is either mm/yyyy, yyyy/mm or yyyy.
is_partial_date( Date, 'my' ) - True if the given date is a month and a year only.
is_partial_date( Date, 'y' ) - True if the given date is a year only.
For example:
D |
is_partial_date( D ) |
is_partial_date( D, 'my' ) |
is_partial_date( D, 'y' ) |
3/11/1990 |
False |
False |
False |
11/1990 |
True |
True |
False |
1990 |
True |
False |
True |
The function full_date converts a partial date to a full date, using a specified day and month to fill in missing values.
full_date( Date, Day1, Day2, Month )
If Date is a full date, the function returns the original date.
If Date is month-year, the function returns a date with the original month and year, and the Day1 value.
If Date is year-only, the function returns a date with the original year, and the Day2 and Month values.
In the following table, assume D1 is a date question with format dd/mm/yyyy:
D1 |
full_date( D1, 15, 30, 6 ) |
11/12/2005 |
11/12/2005 |
12/2005 |
15/12/2005 |
2005 |
30/6/2005 |
For calculating a person’s age from a partial date of birth, the following expression might be used:
time_diff( years, full_date( DOB, 1, 15, 6 ), datenow )
The age will be calculated based on an assumed birthdate of the first of the month where the day is not known, or the 15th of June if only the year is known. However, different study designers can choose to use different defaults for an unknown day and month.
The Arezzo max and min functions work with dates, giving the latest and earliest of a set of dates. However, max and min do not work on sets of dates which include dates of differing partial formats. For max and min to return a correct result, the set of dates must be one of:
all full dates
all month and year
all year only
For any other combinations, max and min will be unknown (and a question derivation based on either function will remain blank).
For example:
D1 |
D2 |
D3 |
max( [D1, D2,D3] ) |
min( [D1, D2,D3] ) |
11/12/2005 |
3/4/2006 |
19/10/2005 |
3/4/2006 |
19/10/2005 |
12/2005 |
4/2006 |
10/2005 |
4/2006 |
10/2005 |
2005 |
2006 |
2005 |
2006 |
2005 |
11/12/2005 |
4/2006 |
19/10/2005 |
- |
- |
2005 |
3/4/2006 |
19/10/2005 |
- |
- |
11/12/2005 |
2006 |
10/2005 |
- |
- |
Related Topics
Arezzo functions and operators in alphabetic order