Date Functions

A guide on date and date and time objects for formulas created in the advanced formula editor in Plecto.

Last updated: Aug. 24, 2021

Date functions, as well as date and time objects, are an integral part of formulas in Plecto. Every value displayed on dashboards or reports comes from a formula. Date functions such as NetWorkDays allow you to further customize the formula to look at data based on a specific date and time, for example, from Monday to Friday, or only for Thursdays.

Note: Using date functions in your formulas does not influence or predetermine the time period on your widgets on dashboards or reports. Date functions allow extracting metrics based on a specific date and time criterion (for example, registrations created from Mondays to Wednesdays), whereas the time period on a widget sets a time frame within which these metrics are displayed (for example, current week, current month, etc.).

Date and time objects

Date and time objects are indicators that tell Plecto what date and time the formula should look at. If it is Today(), Plecto will consider data relative to the current day. If it is StartDate(), Plecto will show data from the starting date and time as the chosen time period on the widget on your dashboard or report.

Here is a list of the available date and time objects:

  • Today() Outputs today's date.
  • Now() Outputs the date and time right now.
  • StartDate() Is the starting date and time selected on the widget.
  • EndDate() Is the ending date and time selected on the widget.
  • Date(<year>,<month>,<day>) Outputs a specific date.

Note: The date and time objects from above cannot be used in an isolated manner - they need to be included in the date functions listed below.

Date functions

Each date function can use almost any of the date and time objects if they follow a logical request. The date and time objects from above can be used in the date functions below.

Days

Days(<start_date>,<end_date>)
Returns the number of days within a given interval. If you select <start_date> and <end_date>, the formula will output a number of days, the number depending on the time period chosen on your widget. For example, if we are currently in June, and the time period on the widget is set to "Current month," this date function will count the number of days in June and display 30.

You can incorporate the following function in your formulas to create, for example, a month-to-date target. Read this article to learn more.

(
    Days(StartDate(),EndDate())
)
NetWorkDays

NetWorkDays(<start_date>,<end_date>)
Returns the number of working days within a selected time period. If you add <start_date> and <end_date> to this function and select "Current month" on the widget, the formula will return a value of 23 for June this year (2021), 22 for August, etc. depending on the number of workdays in the month. Read more about NetWorkDays and how to set up custom working days in this article.

To see the NetWorkDays, you can use the following formula:

(
    NetWorkDays(StartDate(),EndDate())
)
Holidays

Holidays(<country_code>,<start_date>,<end_date>)
Returns the number of holidays within a given interval. This function requires you to indicate a country code, for example, "US", to help Plecto understand from which country it needs to calculate the number of holidays. Find the list of the available country codes in this article.

The widget on your dashboard will display a certain number of Holidays depending on the chosen time period, for example, current week, current month, etc.

To see the number of holidays in the United States, you can use the following formula:

(
    Holidays("US",StartDate(),EndDate())
)
Year

Year(<date>)
Returns the date's year, for example, 2021. To see the year of today, use the following formula:

(
    Year(Today())
)

Tip: Set the number formatting to text to make sure the widget displays, for example, 2021. If you choose the decimal number format instead, the widget will display the result with a thousand separator, for example, 2.021 or 2,021, depending on your localization.

Month

Month(<date>)
Returns the date's month, for example, "8" for August. The result depends on both the date object included in the formula (see the section above) and the time period selected on the widget (current week, current month, etc.).

If you use a formula like the following, it will output a decimal number of the current month. For example, if the current month is August, the widget will display 8.

(
    Month(Today())
)
Day

Day(<date>)
Returns the date's day, for example, "10" for the 10th of June. The result depends on both the date object included in the formula (see the section above) and the time period selected on the widget (current week, current month, etc.).

If you use a formula like the following, it will output a decimal number of the current day. For example, if it is currently the 10th of June, the widget will display 10.

(
    Day(Today())
)

You can also insert other date objects, such as <start_date>, in which case the formula will output a number that is the starting date of the time period chosen on the widget.

Hour

Hour(<date>)
Returns the date's hour, for example, "11" for 11:23 am. This function will return a numerical value of the current hour, and regardless if the hour now is 11:23 am or 11:55 am, it will output a number value of 11.

The following formula will output a number value of the current hour.

(
    Hour(Now())
)

Was this article helpful?