Skip to main content Skip to complementary content

inmonthstodate - script and chart function

This function finds if a timestamp falls within the part a period of the month, bi-month, quarter, four-month period, or half-year up to and including the last millisecond of base_date. It is also possible to find if the timestamp falls within a previous or following time period.

Syntax:  

InMonths (n_months, timestamp, base_date, period_no[, first_month_of_year ])

Return data type: Boolean

Diagram of inmonthstodate function.

Diagram showing how inmonthstodate function can be used to identify if a timstamp falls within or outside of a set segment of time.
Arguments
Argument Description
n_months

The number of months that defines the period. An integer or expression that resolves to an integer that must be one of: 1 (equivalent to the inmonth() function), 2 (bi-month), 3 (equivalent to the inquarter()function), 4 (four-month period), or 6 (half year).

timestamp The date that you want to compare with base_date.
base_date Date that is used to evaluate the period.
period_no

The period can be offset by period_no, an integer, or expression resolving to an integer, where the value 0 indicates the period that contains base_date. Negative values in period_no indicate preceding periods and positive values indicate succeeding periods.

first_month_of_year

If you want to work with (fiscal) years not starting in January, indicate a value between 2 and 12 in first_month_of_year.

In the inmonthstodate() function, the base_date acts as the end point of the particular year segment that it is part of.

For example, if the year was broken into tertial segments, and the base_date was May 15, any timestamp between the start of January and end of April would return a Boolean result of FALSE. Dates between May 1 and May 15 would return TRUE. The rest of the year would return FALSE.

Diagram of Boolean results range of inmonthstodate function.

Diagram showing the range of Boolean results of the inmonthstodate function.

The following segments of the year are available in the function as n_month arguments.

n_month arguments
Period Number of months
month 1
bi-month 2
quarter 3
tertial 4
half-year 6

The inmonthstodate() function returns a Boolean result. Typically, this type of function is used as a condition in an if expression. By using the inmonthstodate() function, you can select the period you want to be evaluated. For example, providing an input variable that lets the user identify the products manufactured in the month, quarter, or half-year of a period, up to a certain date.

Regional settings

Unless otherwise specified, the examples in this topic use the following date format: MM/DD/YYYY. The date format is specified in the SET DateFormat statement in your data load script. The default date formatting may be different in your system, due to your regional settings and other factors. You can change the formats in the examples below to suit your requirements. Or you can change the formats in your load script to match these examples.

Default regional settings in apps are based on the regional system settings of the computer or server where Qlik Sense is installed. If the Qlik Sense server you are accessing is set to Sweden, the Data load editor will use Swedish regional settings for dates, time, and currency. These regional format settings are not related to the language displayed in the Qlik Sense user interface. Qlik Sense will be displayed in the same language as the browser you are using.

Function examples
Example Result
inmonthstodate(4, '01/25/2013', '04/25/2013', 0) Returns True, because the value of timestamp, 01/25/2013, lies within the four-month period 01/01/2013 up to the end of 04/25/2013, in which the value of base_date, 04/25/2013 lies.
inmonthstodate(4, '04/26/2013', '04/25/2006', 0) Returns False, because 04/26/2013 is outside the same period as the previous example.
inmonthstodate(4, '09/25/2005', '02/01/2006', -1) Returns True, because the value of period_no, -1, shifts the search period back one period of four months (the value of n-months), which makes the search period 01/09/2005 to 02/01/2006.
inmonthstodate(4, '04/25/2006', '06/01/2006', 0, 3) Returns True, because the value of first_month_of_year is set to 3, which makes the search period 03/01/2006 to 06/01/2006 instead of 05/01/2006 to 06/01/2006.

Example 1 – No additional arguments

Example 2 – period_no

Example 3 – first_month_of_year

Example 4 – Chart example

Example 5 – Scenario

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!