Discover the power that hides within the
SECOND
function in Google Data Studio. Used to extract the seconds component from a given date, the
SECOND
function simplifies the time analysis process by allowing you to isolate and observe the seconds part of your data. This function is especially handy when you're dealing with precise time-based metrics or when you need granular-level details.
Syntax
The
SECOND
function carries two types of syntax:
-
This syntax is utilized when we want to extract the seconds component from a Date & Time value:
SECOND(datetime_expression)
The datetime_expression
can be either a Date & Time field or expression.
-
This syntax is used for compatibility mode Date value extraction. In addition,
Input Format
is optionally provided in case X isn't appropriately configured as a semantic date field:
SECOND(X [,Input Format])
Here, X
can be a field or expression resulting in Text, Number, or compatibility mode Date. The Input Format
is used to properly interpret the compatibility mode dates.
The
SECOND
function supports various input formats for compatibility mode dates, ranging from 'BASIC', 'DEFAULT_DASH', 'DEFAULT_SLASH', to specific formats like 'RFC_1123', 'RFC_3339', and 'DECIMAL_DATE'. For Numeric fields or expressions, it accepts 'SECONDS', 'MILLIS', 'MICROS', 'NANOS', and 'JULIAN_DATE'.
Usage
Although the Google Data Studio
SECOND
function seems simple, it's a powerful tool to use when dealing with precise time data. To use the function, simply place your Date & Time field or expression within the parentheses (), or for compatibility mode dates, provide your field/expression and optionally, the Input Format.
Examples
Say, you run an online store and want to analyze the precise time when a purchase was made. You have the transaction timestamp which you want to break down.
- To get the seconds part from a date-time expression that is timestamp of the transaction:
SECOND(Transaction_timestamp)
- Suppose the timestamp is in text format like "2022/01/01-14:20:45". To get the seconds:
SECOND("2022/01/01-14:20:45", 'BASIC')
- When the timestamp is stored as milliseconds since the Epoch:
SECOND(Transaction_timestamp_millis, 'MILLIS')
Remember, the function will return a result between 0-59 which represents the seconds component of the date.
Function Limitations
Keep in mind that the
SECOND
function is designed to only retrieve the 'seconds' portion of a dateime. It won't return minutes, hours, or any other components. Also, it works with both compatibility mode dates and upgraded Date and Date & Time data types.
Helpful Tips
Some tips to keep in mind:
- Make sure to match the correct input format with the data type of your source field or expression.
- Deployment of the
SECOND
function can be especially beneficial when coupled with other time-based functions for comprehensive time-series analysis.
- Use
SECOND
function in calculated fields to create new metrics at granular level.
Remember, every second counts, and so does the
SECOND
function in Google Data Studio! Compute wisely!