Formats recognized date fields (19 formats recognized) to a specified date format using strftime date format specifiers.
Table of Contents | Source: src/cmd/datefmt.rs | 📇🚀👆
Description | Examples | Usage | Arguments | Datefmt Options | Common Options
Description ↩
Formats recognized date fields (19 formats recognized) to a specified date format using strftime date format specifiers.
For recognized date formats, see https://github.com/dathere/qsv-dateparser?tab=readme-ov-file#accepted-date-formats
See https://docs.rs/chrono/latest/chrono/format/strftime/ for accepted date format specifiers for --formatstr. Defaults to ISO 8601/RFC 3339 format when --formatstr is not specified. ( "%Y-%m-%dT%H:%M:%S%z" - e.g. 2001-07-08T00:34:60.026490+09:30 )
Examples ↩
Format dates in Open Date column to ISO 8601/RFC 3339 format:
qsv datefmt 'Open Date' file.csvFormat multiple date columns in file.csv to ISO 8601/RFC 3339 format:
qsv datefmt 'Open Date,Modified Date,Closed Date' file.csvFormat all columns that end with "_date" case-insensitive in file.csv to ISO 8601/RFC 3339 format:
qsv datefmt '/(?i)_date$/' file.csvFormat dates in OpenDate column using '%Y-%m-%d' format:
qsv datefmt OpenDate --formatstr '%Y-%m-%d' file.csvFormat multiple date columns using '%Y-%m-%d' format:
qsv datefmt OpenDate,CloseDate,ReopenDate --formatstr '%Y-%m-%d' file.csvGet the week number for OpenDate and store it in the week_number column:
qsv datefmt OpenDate --formatstr '%V' --new-column week_number file.csvGet the day of the week for several date columns and store it in the corresponding weekday columns:
qsv datefmt OpenDate,CloseDate --formatstr '%u' --rename Open_weekday,Close_weekday file.csvFor more examples, see tests.
Usage ↩
qsv datefmt [--formatstr=<string>] [options] <column> [<input>]
qsv datefmt --helpArguments ↩
| Argument | Description |
|---|---|
<column> |
The column/s to apply the date formats to. Note that the argument supports multiple columns. See 'qsv select --help' for the format details. |
<input> |
The input file to read from. If not specified, reads from stdin. |
Datefmt Options ↩
| Option | Type | Description | Default |
|---|---|---|---|
‑c,‑‑new‑column |
string | Put the transformed values in a new column instead. | |
‑r,‑‑rename |
string | New name for the transformed column. | |
‑‑prefer‑dmy |
flag | Prefer to parse dates in dmy format. Otherwise, use mdy format. | |
‑‑keep‑zero‑time |
flag | If a formatted date ends with "T00:00:00+00:00", keep the time instead of removing it. | |
‑‑input‑tz=<string> |
string | The timezone to use for the input date if the date does not have timezone specified. The timezone must be a valid IANA timezone name or the string "local" for the local timezone. See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for a list of valid timezone names. | UTC |
‑‑output‑tz=<string> |
string | The timezone to use for the output date. The timezone must be a valid IANA timezone name or the string "local". | UTC |
‑‑default‑tz=<string> |
string | The timezone to use for BOTH input and output dates when they do have timezone. Shortcut for --input-tz and --output-tz set to the same timezone. The timezone must be a valid IANA timezone name or the string "local". | |
‑‑utc |
flag | Shortcut for --input-tz and --output-tz set to UTC. | |
‑‑zulu |
flag | Shortcut for --output-tz set to UTC and --formatstr set to "%Y-%m-%dT%H:%M:%SZ". | |
‑R,‑‑ts‑resolution |
string | The resolution to use when parsing Unix timestamps. Valid values are "sec", "milli", "micro", "nano". | sec |
‑j,‑‑jobs |
string | The number of jobs to run in parallel. When not set, the number of jobs is set to the number of CPUs detected. | |
‑b,‑‑batch |
string | The number of rows per batch to load into memory, before running in parallel. Automatically determined for CSV files with more than 50000 rows. Set to 0 to load all rows in one batch. Set to 1 to force batch optimization even for files with less than 50000 rows. | 50000 |
Common Options ↩
| Option | Type | Description | Default |
|---|---|---|---|
‑h,‑‑help |
flag | Display this message | |
‑o,‑‑output |
string | Write output to instead of stdout. | |
‑n,‑‑no‑headers |
flag | When set, the first row will not be interpreted as headers. | |
‑d,‑‑delimiter |
string | The field delimiter for reading CSV data. Must be a single character. (default: ,) | |
‑p,‑‑progressbar |
flag | Show progress bars. Not valid for stdin. |
Source: src/cmd/datefmt.rs
| Table of Contents | README