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
  • Language Reference Guide
    • Readme
    • Types in the Nu Language
      • Basic Types
        • Any
        • Boolean
        • Integer
        • Float
        • Filesize
        • Duration
        • Datetime
        • Range
        • String
        • Record
        • List
        • Table
        • Closure
        • Nothing
        • Binary
        • Glob
        • Cell-Path
      • Other Data Types

        • Types that cannot be used to declare variables
          • Path
        • Types which are not declarable
          • Error
          • CustomValue
          • Block
      • Type signatures
      • Commands that interact with types
    • Operators
    • Flow control
      • if/else
      • loop
      • while
      • match
      • try/catch
      • break
      • return
      • continue
    • Filters
      • each and par-each
      • Filters to select subsets of data
      • where and filter
      • Understanding the difference between get and select
    • Custom Commands
    • Declarations
    • Variable Scope
    • Strings and Text Formatting
    • Helpers and debugging commands
    • Pipelines
    • MIME Types for Nushell

Duration

Description:Represent a unit of a passage of time
Annotation:duration
Literal Syntax:A numeric (integer or decimal) literal followed immediately by a duration unit (listed below). E.g., 10sec, 987us, -34.65day
Casts:into duration
See also:Types of Data - Durations

Additional Language Notes

  1. Durations are internally stored as a number of nanoseconds.

  2. This chart shows all duration units currently supported:

    DurationLength
    nsnanosecond
    us/μsmicrosecond
    msmillisecond
    secsecond
    minminute
    hrhour
    dayday
    wkweek
  3. Datetime values can be combined with durations in calculations:

    > (date now) + 1day
    Tue, 13 Aug 2024 11:49:27 -0400 (in a day)
    > 2024-08-12T11:50:30-04:00 - 2019-05-10T09:59:12-07:00
    274wk 2day 22hr 51min 18sec
  4. Months, years, centuries and millenniums are not precise as to the exact number of nanoseconds and thus are not valid duration literals. Users are free to define their own constants for specific months or years.

Common commands that can be used with duration

  • sleep
  • ps
  • sys

Operators that can be used with duration

  • ==, !=, <, <=, >, >=
  • +, -
Edit this page on GitHub
Contributors: NotTheDr01ds, fdncred
Prev
Filesize
Next
Datetime