Time.From

D

T

The M Code Behind the Power Query M function Time.From

What is M code?

M code is the programming language used in Power Query to transform data. It is a functional language that is used to define queries, which are then executed against data sources. M code is similar to other functional programming languages, such as F# and Haskell, and it is designed to be easy to read and understand.

How does the Time.From function work?

The Time.From function takes a datetime value as its input and returns a time value. The datetime value can be any valid datetime value, such as a date and time value, or a datetimezone value. The time value that is returned by the function represents the time component of the input datetime value.

The M code behind the Time.From function is relatively simple. Here is the code:


(Time as datetime) => Time.TimeOfDay


The function takes a single argument, which is a datetime value, and returns the TimeOfDay property of the datetime value. The TimeOfDay property is a time value that represents the time component of the datetime value.

Examples

Let’s take a look at some examples of how the Time.From function works. Suppose we have a table of datetime values, and we want to extract the time component of each value. We can use the Time.From function to achieve this:


let

Source = Table.FromRows({{#datetime(2022, 1, 1, 12, 30, 0)}, {#datetime(2022, 1, 1, 14, 45, 0)}, {#datetime(2022, 1, 1, 16, 0, 0)}}),

#"Renamed Columns" = Table.RenameColumns(Source,{{"Column1", "DateTime"}}),

#"Added Custom" = Table.AddColumn(#"Renamed Columns", "Time", each Time.From([DateTime]))

in

#"Added Custom"


This code creates a table with three rows of datetime values and then uses the Time.From function to extract the time component of each value. The resulting table has two columns: DateTime and Time.

The Time.From function is a powerful tool in Power Query that allows you to extract the time component of datetime values. The M code behind the function is simple and easy to understand. By using the Time.From function in your Power Query queries, you can easily manipulate datetime values and extract the information that you need.

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)