Start a conversation

Calculations with date and time

  • Doing date (and time) calculations: the basics

    Calculation fields in Castor are often used to build advanced date validations. In Castor dates are stored as string (text) in the format 'DD-MM-YYYY'. It is generally necessary to indicate this in yo...

  • Calculate the difference between two dates

    There are multiple options to calculate the difference between dates. 1. getDateDiff The easiest approach is to use getDateDiff. See this calculation: getDateDiff('{date2}','{date1}','y') In this calc...

  • Calculate time difference between two time fields

    Time difference between two time fields on the same day To calculate the difference between two time fields in hours, minutes, or seconds, use the following formula: getTimeDiff('{time_variable_2}', '...

  • Add a month to a date

    Use this template to add a month to a date, e.g. if the next visit has to be within a month after the first visit. Replace {date} with your own variable name. var date = moment('{date}', 'DD-MM-YYYY')...

  • Using if/else logic with dates

    You can use Moment.js to compare two or three dates with each other. You can use this to build advanced dependencies or calculations.  How to start More information about how to create a Moment.js obj...

  • Calculate the age using a date variable

    There are multiple ways to calculate the age using dates. Here are some examples: Calculate current age (today's age) If you only have one date variable (date of birth), you can use the following form...

  • Calculate the age using a year (or year and month) variable

    As a full birth date might be considered personally identifiable information, using only the birth year or year and month of birth is a good alternative. It is still possible to calculate the age from...

  • Check if a date is before another date and show an error if so

    1. Create a calculation field after two date fields. You can choose the variable names yourself, but you will have to change them in the calculation template in step 2. 2. Use this formula for the cal...

  • Show a message when the date is more than X days before today or in the future

    If you want to give a message when the date is more than X days before today, or in the future, you can use this formula. In this example 10 days or more are used as the limit.  You can enter your var...

  • Check if the difference between two dates is between limits

    This template checks if after the patient signed informed consent (date1) a visit has taken place (date2) between a day range.  In this template: date1 and date2 are two date fields in your form. Repl...