datefmt

May 31, 2026 · View on GitHub

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.csv

Format multiple date columns in file.csv to ISO 8601/RFC 3339 format:

qsv datefmt 'Open Date,Modified Date,Closed Date' file.csv

Format all columns that end with "_date" case-insensitive in file.csv to ISO 8601/RFC 3339 format:

qsv datefmt '/(?i)_date$/' file.csv

Format dates in OpenDate column using '%Y-%m-%d' format:

qsv datefmt OpenDate --formatstr '%Y-%m-%d' file.csv

Format multiple date columns using '%Y-%m-%d' format:

qsv datefmt OpenDate,CloseDate,ReopenDate --formatstr '%Y-%m-%d' file.csv

Get the week number for OpenDate and store it in the week_number column:

qsv datefmt OpenDate --formatstr '%V' --new-column week_number file.csv

Get 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.csv

For more examples, see tests.

See also https://github.com/dathere/qsv/wiki/Transform-and-Reshape#datefmt

Usage

qsv datefmt [--formatstr=<string>] [options] <column> [<input>]
qsv datefmt --help

Arguments

 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         TypeDescriptionDefault
 ‑c,
‑‑new‑column 
stringPut the transformed values in new column(s) instead of replacing the source column(s). When the selection has multiple columns, pass a comma-separated list of new column names that match the selection count (e.g. --new-column 'open_iso,close_iso' for 'OpenDate,CloseDate'). To rename in place instead, use --rename.
 ‑r,
‑‑rename 
stringNew name for the transformed column.
 ‑‑prefer‑dmy flagPrefer to parse dates in dmy format. Otherwise, use mdy format.
 ‑‑keep‑zero‑time flagIf a formatted date ends with "T00:00:00+00:00", keep the time instead of removing it.
 ‑‑input‑tz=<string> stringThe 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> stringThe timezone to use for the output date. The timezone must be a valid IANA timezone name or the string "local".UTC
 ‑‑default‑tz=<string> stringFallback timezone consulted only when --input-tz or --output-tz is set to "local" but local-timezone detection fails. Defaults to UTC. Does NOT override the --input-tz / --output-tz defaults — use --utc to force both input and output to UTC. The timezone must be a valid IANA timezone name or the string "local".
 ‑‑utc flagShortcut for --input-tz and --output-tz set to UTC.
 ‑‑zulu flagShortcut for --output-tz set to UTC and --formatstr set to "%Y-%m-%dT%H:%M:%SZ".
 ‑R,
‑‑ts‑resolution 
stringThe resolution to use when parsing Unix timestamps. Valid values are "sec", "milli", "micro", "nano".sec
 ‑j,
‑‑jobs 
integerThe number of jobs to run in parallel. When not set, the number of jobs is set to the number of CPUs detected.
 ‑b,
‑‑batch 
integerThe 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     TypeDescriptionDefault
 ‑h,
‑‑help 
flagDisplay this message
 ‑o,
‑‑output 
stringWrite output to instead of stdout.
 ‑n,
‑‑no‑headers 
flagWhen set, the first row will not be interpreted as headers.
 ‑d,
‑‑delimiter 
stringThe field delimiter for reading CSV data. Must be a single character. (default: ,)
 ‑p,
‑‑progressbar 
flagShow progress bars. Not valid for stdin.

Source: src/cmd/datefmt.rs | Table of Contents | README