W3cubDocs

/Nushell

dfr datepart for expression

Creates an expression for capturing the specified datepart in a column.

Signature

> dfr datepart {flags} (Datepart name)

Parameters

  • Datepart name: Part of the date to capture. Possible values are year, quarter, month, week, weekday, day, hour, minute, second, millisecond, microsecond, nanosecond

Input/output types:

input output
any any

Examples

Creates an expression to capture the year date part

> [["2021-12-30T01:02:03.123456789"]] |dfr into-df|dfr as-datetime"%Y-%m-%dT%H:%M:%S.%9f"|dfr with-column [(dfr coldatetime|dfr datepartyear|dfr asdatetime_year )]
╭───┬─────────────┬───────────────╮
# │  datetime   │ datetime_year │
├───┼─────────────┼───────────────┤
02yearsago2021
╰───┴─────────────┴───────────────╯

Creates an expression to capture multiple date parts

> [["2021-12-30T01:02:03.123456789"]] |dfr into-df|dfr as-datetime"%Y-%m-%dT%H:%M:%S.%9f"|
dfr with-column [ (dfr coldatetime|dfr datepartyear|dfr asdatetime_year ),
                (dfr coldatetime|dfr datepartmonth|dfr asdatetime_month ),
                (dfr coldatetime|dfr datepartday|dfr asdatetime_day ),
                (dfr coldatetime|dfr dateparthour|dfr asdatetime_hour ),
                (dfr coldatetime|dfr datepartminute|dfr asdatetime_minute ),
                (dfr coldatetime|dfr datepartsecond|dfr asdatetime_second ),
                (dfr coldatetime|dfr datepartnanosecond|dfr asdatetime_ns ) ]
╭─────┬───────────────┬────────────────┬─────────────────┬───────────────┬────────────────┬──────────────────┬──────╮
# │   datetime    │ datetime_year  │ datetime_month  │ datetime_day  │ datetime_hour  │ datetime_minute  │ ...  │
├─────┼───────────────┼────────────────┼─────────────────┼───────────────┼────────────────┼──────────────────┼──────┤
02yearsago2021123012...
╰─────┴───────────────┴────────────────┴─────────────────┴───────────────┴────────────────┴──────────────────┴──────╯

Tips: Dataframe commands were not shipped in the official binaries by default, you have to build it with --features=dataframe flag

Copyright © 2019–2023 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/dfr_datepart.html