Home Explore Blog CI



nushell

3rd chunk of `book/types_of_data.md`
c842dfd95a84d34c12d1b2d450d258e1cfe222e33f49bdcb000000010000100a
# => Hello, World
```

### Booleans

|                       |                                                                                |
| --------------------- | ------------------------------------------------------------------------------ |
| **_Description:_**    | True or False value                                                            |
| **_Annotation:_**     | `bool`                                                                         |
| **_Literal Syntax:_** | Either a literal `true` or `false`                                             |
| **_See also:_**       | [Language Reference - Boolean](/lang-guide/chapters/types/basic_types/bool.md) |

Booleans are commonly the result of a comparison. For example:

```nu
let mybool: bool = (2 > 1)
$mybool
# => true
let mybool: bool = ($env.HOME | path exists)
$mybool
# => true
```

A boolean result is commonly used to control the flow of execution:

```nu
let num = -2
if $num < 0 { print "It's negative" }
# => It's negative
```

### Dates

|                       |                                                                                        |
| --------------------- | -------------------------------------------------------------------------------------- |
| **_Description:_**    | Represents a specific point in time using international standard date-time descriptors |
| **_Annotation:_**     | `datetime`                                                                             |
| **_Literal Syntax:_** | See [Language Guide - Date](/lang-guide/chapters/types/basic_types/datetime.md)        |

Simple example:

```nu
date now
# => Mon, 12 Aug 2024 13:59:22 -0400 (now)
# Format as Unix epoch
date now | format date '%s'
# => 1723485562
```

### Durations

|                       |                                                                                           |
| --------------------- | ----------------------------------------------------------------------------------------- |
| **_Description:_**    | Represent a unit of a passage of time                                                     |
| **_Annotation:_**     | `duration`                                                                                |
| **_Literal Syntax:_** | See [Language Reference - Duration](/lang-guide/chapters/types/basic_types/duration.html) |

Durations support fractional values as well as calculations.

Simple example:

```nu
3.14day
# => 3day 3hr 21min
30day / 1sec  # How many seconds in 30 days?
# => 2592000
```

### File sizes

|                       |                                                                                           |
| --------------------- | ----------------------------------------------------------------------------------------- |
| **_Description:_**    | Specialized numeric type to represent the size of files or a number of bytes              |
| **_Annotation:_**     | `filesize`                                                                                |
| **_Literal Syntax:_** | See [Language Reference - Filesize](/lang-guide/chapters/types/basic_types/filesize.html) |

Nushell also has a special type for file sizes.

As with durations, Nushell supports fractional file sizes and calculations:

```nu
0.5kB
# => 500 B
1GiB / 1B
# => 1073741824
(1GiB / 1B) == 2 ** 30
# => true
```

See the [Language Reference](/lang-guide/chapters/types/basic_types/filesize.html) for a complete list of units and more detail.

### Ranges

|                       |                                                                                                |
| --------------------- | ---------------------------------------------------------------------------------------------- |
| **_Description:_**    | Describes a range of values from a starting value to an ending value, with an optional stride. |
| **_Annotation:_**     | `range`                                                                                        |
| **_Literal Syntax:_** | `<start_value>..<end_value>`. E.g., `1..10`.                                                   |

Title: Basic Data Types Continued: Booleans, Dates, Durations, File sizes, and Ranges
Summary
This section of the Nushell documentation covers booleans, dates, durations, file sizes, and ranges. Booleans are true/false values used for comparisons and control flow. Dates represent specific points in time, while durations represent passages of time, both supporting formatting and calculations. File sizes are specialized numeric types representing file or byte sizes. Ranges describe a sequence of values from a starting value to an ending value.