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...

  • 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...

  • 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...

  • Add hours and minutes to a datetime field

    If you want to add hours and minutes to a date & time field, you can use this template. For this calculation, you will need a date & time field and a time field which are called 'datetime' and 'add_ti...

  • 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'...

  • Subtract a month from a date

    See here how you can add a month to a date: Add a month to a date. Use this template to subtract a month from a date. Replace {date} with your own variable name. var date = moment('{date}', 'DD-MM-YYY...

  • Adding hours or minutes to a time field

    To add hours or minutes to the time entered into a time field, you can use the following calculation template. For example, use this template to add 15 minutes: var addHours = moment('{your_time_varia...

  • Extract only date or time from date and time field

    If you want to extract a part of a date and time field (i.e. the date only, or the time only), you can use the following templates. Replace {your_datetime_variable} with your own variable name. To ext...

  • Check if year is in the future

    To validate whether a year is in the future you can use the following calculation template: var year = moment('{year_field}').format('YYYY'); var year_now = moment().format('YYYY'); if (year > year_no...