DateTime.IsInNextNMinutes

D

T

The M Code Behind the Power Query M function DateTime.IsInNextNMinutes

The M code behind this function is relatively straightforward, but it can be useful to understand how it works if you want to modify it or create your own custom date and time functions in Power Query M.

The Function Syntax

Before we dive into the M code behind DateTime.IsInNextNMinutes, let’s take a look at the function syntax:


DateTime.IsInNextNMinutes(dateTime as any, minutes as number) as logical


This function takes two arguments:

- `dateTime`: The date and time value that you want to check.

- `minutes`: The number of minutes from the current date and time that you want to check.

The function returns a logical value (`true` or `false`) depending on whether the specified date and time value falls within the specified number of minutes from the current date and time.

The M Code

Now let's take a look at the M code behind this function:


(dateTime – DateTime.LocalNow()) / Duration.FromMinutes(1) < minutes


This code may look a bit intimidating at first, but it's actually quite simple. Let's break it down:

- `DateTime.LocalNow()` returns the current date and time value.

- `dateTime - DateTime.LocalNow()` subtracts the current date and time value from the specified date and time value, resulting in the time difference between the two values.

- `(dateTime - DateTime.LocalNow()) / Duration.FromMinutes(1)` converts the time difference to minutes.

- `< minutes` checks if the time difference is less than the specified number of minutes.

If the time difference is less than the specified number of minutes, the function returns `true`. Otherwise, it returns `false`.

Modifying the Function

If you want to modify the DateTime.IsInNextNMinutes function, you can do so by changing the M code. For example, if you want to check if a given date and time value falls within the specified number of hours from the current date and time, you can modify the code like this:


(dateTime – DateTime.LocalNow()) / Duration.FromHours(1) < hours


Here, we have replaced `Duration.FromMinutes(1)` with `Duration.FromHours(1)` and changed the function argument to `hours`.

The DateTime.IsInNextNMinutes function in Power Query M allows you to check if a given date and time value falls within the specified number of minutes from the current date and time. The M code behind this function is relatively simple, but it can be useful to understand how it works if you want to modify it or create your own custom date and time functions in Power Query M.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)