DateTime.LocalNow

DateTime

Returns the current local date and time.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

DateTime.LocalNow() as datetime

Return Value

datetimeThe current local date and time.

Remarks

DateTime.LocalNow returns the current date and time on the machine where the query is executed. The value changes each time the query runs, so it cannot be used for reproducible results. It is commonly used for calculating elapsed time, adding refresh timestamps, or computing ages relative to the current moment.

Examples

Example 1: Display the current local datetime

#table(
    type table [CurrentDateTime = datetime],
    {{DateTime.LocalNow()}}
)
Result
CurrentDateTime
17/15/2024 10:30:00 AM

Example 2: Calculate days since each order

let
    Now = #datetime(2024, 7, 15, 10, 30, 0) // DateTime.LocalNow()
in
    Table.AddColumn(
        Table.SelectColumns(
            Table.FirstN(Sales, 4),
            {"OrderID", "OrderDate"}
        ),
        "DaysSinceOrder",
        each Duration.Days(Now - DateTime.From([OrderDate])),
        Int64.Type
    )
Result
OrderID
OrderDate
DaysSinceOrder
111/15/2024182
221/18/2024179
332/1/2024165
442/10/2024156

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks