Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

polars datepart for expression

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

This command requires a plugin

The polars datepart command resides in the polars plugin. To use this command, you must install and register nu_plugin_polars. See the Plugins chapter in the book for more information.

Signature

> polars 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:

inputoutput
anyany

Examples

Creates an expression to capture the year date part

> [["2021-12-30T01:02:03.123456789"]] | polars into-df | polars as-datetime "%Y-%m-%dT%H:%M:%S.%9f" --naive | polars with-column [(polars col datetime | polars datepart year | polars as datetime_year )]
╭───┬─────────────┬───────────────╮
│ # │  datetime   │ datetime_year │
├───┼─────────────┼───────────────┤
│ 0 │ 3 years ago │          2021 │
╰───┴─────────────┴───────────────╯

Creates an expression to capture multiple date parts

> [["2021-12-30T01:02:03.123456789"]] | polars into-df | polars as-datetime "%Y-%m-%dT%H:%M:%S.%9f" --naive |
                polars with-column [ (polars col datetime | polars datepart year | polars as datetime_year ),
                (polars col datetime | polars datepart month | polars as datetime_month ),
                (polars col datetime | polars datepart day | polars as datetime_day ),
                (polars col datetime | polars datepart hour | polars as datetime_hour ),
                (polars col datetime | polars datepart minute | polars as datetime_minute ),
                (polars col datetime | polars datepart second | polars as datetime_second ),
                (polars col datetime | polars datepart nanosecond | polars as datetime_ns ) ]
╭───┬─────────────┬───────────────┬────────────────┬──────────────┬───────────────┬─────────────────┬───────────┬─────╮
│ # │  datetime   │ datetime_year │ datetime_month │ datetime_day │ datetime_hour │ datetime_minute │ datetime_ │ dat │
│   │             │               │                │              │               │                 │ second    │ eti │
│   │             │               │                │              │               │                 │           │ me_ │
│   │             │               │                │              │               │                 │           │ ns  │
├───┼─────────────┼───────────────┼────────────────┼──────────────┼───────────────┼─────────────────┼───────────┼─────┤
│ 0 │ 3 years ago │          2021 │             12 │           30 │             1 │               2 │         3 │ 123 │
│   │             │               │                │              │               │                 │           │ 456 │
│   │             │               │                │              │               │                 │           │ 789 │
╰───┴─────────────┴───────────────┴────────────────┴──────────────┴───────────────┴─────────────────┴───────────┴─────╯