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 as-date for dataframe

Converts string to date.

This command requires a plugin

The polars as-date 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 as-date {flags} (format)

Flags

  • --not-exact, -n: the format string may be contained in the date (e.g. foo-2021-01-01-bar could match 2021-01-01)

Parameters

  • format: formatting date string

Input/output types:

inputoutput
dataframedataframe
expressionexpression

Examples

Converts string to date

> ["2021-12-30" "2021-12-31"] | polars into-df | polars as-date "%Y-%m-%d"
╭───┬─────────────╮
│ # │    date     │
├───┼─────────────┤
│ 0 │ 3 years ago │
│ 1 │ 3 years ago │
╰───┴─────────────╯

Converts string to date

> ["2021-12-30" "2021-12-31 21:00:00"] | polars into-df | polars as-date "%Y-%m-%d" --not-exact
╭───┬─────────────╮
│ # │    date     │
├───┼─────────────┤
│ 0 │ 3 years ago │
│ 1 │ 3 years ago │
╰───┴─────────────╯

Converts string to date in an expression

> ["2021-12-30" "2021-12-31 21:00:00"] | polars into-lazy | polars select (polars col 0 | polars as-date "%Y-%m-%d" --not-exact)
╭───┬─────────────╮
│ # │    date     │
├───┼─────────────┤
│ 0 │ 3 years ago │
│ 1 │ 3 years ago │
╰───┴─────────────╯

Output is of date type

> ["2021-12-30" "2021-12-31 21:00:00"] | polars into-df | polars as-date "%Y-%m-%d" --not-exact | polars schema
╭──────┬──────╮
│ date │ date │
╰──────┴──────╯

Notes

Format example: "%Y-%m-%d" => 2021-12-31 "%d-%m-%Y" => 31-12-2021 "%Y%m%d" => 2021319 (2021-03-19)