# Time.Second

## #

The Time.Second function is a part of the M language, which is used in Power Query to create custom functions and manipulate data. In this article, we will explore the M code behind the Time.Second function and how it works.

## The Syntax of Time.Second Function

The Time.Second function has a simple syntax. It takes a time value as an argument and returns the number of seconds since midnight of that time. Here is the syntax of the Time.Second function:

``` Time.Second(time as any) as any ```

The “time” argument can be any valid time value, including a date/time value, a time value, or a datetimezone value.

## How Time.Second Works

The Time.Second function works by converting the given time value to the number of seconds since midnight. Here is the M code behind the Time.Second function:

``` (Time.Hour(time) 3600) + (Time.Minute(time) 60) + Time.Second(time) ```

As you can see, the M code first calculates the number of seconds in the hours component of the time value by multiplying it by 3600. It then calculates the number of seconds in the minutes component of the time value by multiplying it by 60. Finally, it adds the number of seconds in the seconds component of the time value.

The result is the total number of seconds since midnight of the given time value.

## Examples of Using Time.Second Function

Let’s look at some examples of using the Time.Second function in Power Query.

### Example 1: Using Time.Second with a Time Value

Suppose we have a time value of 10:30:15 AM. We can use the Time.Second function to find the number of seconds since midnight of this time value. Here is the M code for this:

``` let timeValue = #time(10, 30, 15), secondsSinceMidnight = Time.Second(timeValue) in secondsSinceMidnight ```

The result of this query is 37815, which is the number of seconds since midnight of 10:30:15 AM.

### Example 2: Using Time.Second with a Date/Time Value

Suppose we have a date/time value of 3/14/2021 11:45:30 AM. We can use the Time.Second function to find the number of seconds since midnight of this date/time value. Here is the M code for this:

``` let dateTimeValue = #datetime(2021, 3, 14, 11, 45, 30), timeValue = Time(dateTimeValue), secondsSinceMidnight = Time.Second(timeValue) in secondsSinceMidnight ```

The result of this query is 42330, which is the number of seconds since midnight of 11:45:30 AM on March 14, 2021.

The Time.Second function is a powerful tool in Power Query that allows users to find the number of seconds since midnight of a given time value. By understanding the M code behind the function, users can customize it to suit their specific needs and create more powerful data processing queries.

Subject