Skip to content

current_timestamp

laktory.narwhals_ext.functions.current_timestamp ¤

FUNCTION DESCRIPTION
current_timestamp

Returns the current timestamp at the start of expression evaluation as a timestamp.

current_timestamp() ¤

Returns the current timestamp at the start of expression evaluation as a timestamp.

RETURNS DESCRIPTION
Expr

Current timestamp

Examples:

import narwhals as nw
import polars as pl

import laktory as lk  # noqa: F401

df = nw.from_native(pl.DataFrame({"x": [0, 1]}))
df = df.with_columns(tstamp=nw.laktory.current_timestamp())

# print(df)
Source code in laktory/narwhals_ext/functions/current_timestamp.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def current_timestamp() -> nw.Expr:
    """
    Returns the current timestamp at the start of expression evaluation as a timestamp.

    Returns
    -------
    :
        Current timestamp

    Examples
    --------
    ```py
    import narwhals as nw
    import polars as pl

    import laktory as lk  # noqa: F401

    df = nw.from_native(pl.DataFrame({"x": [0, 1]}))
    df = df.with_columns(tstamp=nw.laktory.current_timestamp())

    # print(df)
    ```
    """
    return nw.lit(utc_datetime())