Working with date functions in Airtable
  • 16 Sep 2024
  • 4 Minutes to read
  • Dark
    Light
  • PDF

Working with date functions in Airtable

  • Dark
    Light
  • PDF

Article summary

Plan availability

All plan types

Platform(s)

Web/Browser, Mac app, and Windows app

Related reading

Getting started with formulas

In this article, we’ll take a look at functions that will help you work with dates and times. As you learn about these functions, feel free to try them out to practice in a formula field in one of your tables that contains a date and time field. Please refer to this section of the formula field reference article to understand the specifics about each function covered in the article below.

Date functions can be split up into four primary categories:

  1. Returning specific datetimes

  2. Formatting strings

  3. Adding or subtracting dates

  4. Returning dates

In the following sections, we’ll go over functions that belong in each of those categories. If you’d like to skip to a specific section, just click on its name in the last above.

Returning datetimes in Airtable

These functions return a specified value according to the referenced datetime. For example, if you wanted to return the month of every completion date in a table, you would write: MONTH({Completion date}).

Here are the functions that work in this way:

  • YEAR()

  • MONTH()

  • DAY()

  • HOUR()

  • MINUTE()

  • SECOND()

To practice, enter a few dates into a table, and use a few of these functions to output a different result. Since they all work similarly you don't necessarily need to practice each one - but knowing how the work categorically is key.

Formatting strings in Airtable

The functions below format datetimes into specific strings - either as a time, or as a date.

  • TIMESTR()

  • DATESTR()

For example, if you wanted to format the current date and time provided by NOW() only as the time, you would use this formula:

TIMESTR(NOW ())

Using the dates you listed in the previous section, practice using these two functions to format the dates in different ways.

Returning dates in Airtable

These last date and time functions can be used to return the day or week of the year according to whatever datetime they reference.

  • WEEKDAY(): return the day of the week

  • WEEKNUM(): return the week of the year

For example, if you want to organize a table by week of the year, you would use a formula like this:

WEEKNUM  ({Date})

Adding or subtracting time from dates

The DATEADD() function, allows you to add specified "count" units to a datetime. See the list of shared unit specifiers here. For this function we recommend using the full unit specifier, (i.e. use "years" instead of "y"), for your desired unit.

For example, if you wanted to automatically calculate an SLA due date by adding 2 weeks of time to the day a request was created then you might make a formula similar to this:

DATEADD({Created date}, 2, "weeks")

Alternatively, if you wanted to subtract time from a date, say if you were wanting to calculate a 1 week out reminder when a task or project is due, then you would create a formula like this:

DATEADD({Due date}, -1, "weeks")

Notice, that there is a hyphen in front of the number you specify to make the number negative.

Returning workdays in Airtable

This function doesn't quite fit with the other categories, and works similarly the DATEADD() function covered previously.

You can use WORKDAY() to return the date after a specific number of working days. For example, if you wanted to always calculate a 30 working days after a start date, you would use a formula like this:

WORKDAY({Start Date}, 30)

Working days exclude weekends and an optional list of holidays, formatted as a comma-separated string of ISO-formatted dates (similar to WORKDAY_DIFF()).

Datetimes practice in Airtable

Want to practice working with datetimes? Setup a base that leverages an IF statement along with this function to output different dates. Follow these steps:

  1. Create a random list of 10 dates in a {Start Date} field

  2. Create a single select field with values of Type 1 and Type 2

  3. For 5 records, assign Type 1

  4. For 5 records, assign Type 2

Next, create a formula to output a different number of working days depending on the type:

  • For Type 1 records, add 7 days

  • For Type 2 records, add 14 days

What formula did you come up with? If you’re having trouble, or simply want to check your work, you can click the box below to see a correct formula.
WORKDAY() Formula

`IF({Type}="Type 1", WORKDAY({Start Date}, 7), IF({Type}="Type 2", WORKDAY({Start Date}, 14), {Start Date}))`

FAQs

Can I add a duration field’s value to a date field?

Yes, but you need to follow a particular format in the DATEADD() formula to get it to output correctly. Duration fields are formatted in seconds. So the unit specifier at the end of the formula should be “seconds".

For example, let’s say that you want to add a “Task duration” field’s value to a “Submission date” field so that there is a rough estimate of when the task can be completed by. In this simple example, you could use the following formula:

DATEADD({Submission date}, {Task duration}, "seconds")

Note

Make sure that the “Timezones” match in the DATEADD() formula you are creating if the “Formatting” setting to “Use the same time zone for all collaborators” is enabled on the date field (in this case the “Submission date” field) you are adding time to.


Was this article helpful?