date_format

Commands ››
Parent Previous Next

The date_format command is used to format dates in various ways. The command requires that dates in the CSV input are in ISO YYYY-MM-DD format. You can convert dates to this format using the date_iso command.

See also: date_iso

Flag

Req'd?

Description

-f fields

Yes

A comma-separated list of fields to attempt to format. If a specified field does not contain a valid date in ISO YYYY-MM-DD format, it is not converted.

-fmt format

Yes

A format specification. The formatters currently available are as follows;

d - day as 1 or 2 digits
dd - day with leading zero
m - month as 1 or digits
mm - month with leading zero
mmm - month as 3-char code e.g. Jan, Aug
M - full month name
w - weekday as 3-char code e.g. Mon, Tue
W - full weekday name
y - 4-digit year
yyyy - 4 digit year

Note 2-digit years are not currently supported.

All other characters are treated literally.



The following example takes the file birthdays.csv, converts it to ISO format and then pipes the resulting output into another CSVfix command which outputs the birthday field in the form "Mon 3 Jun 2009" (please note the pipe symbol in the command line):

csvfix date_iso -f 2 -m 'd/m/y' data/birthdays.csv |
csvfix date_format -f 2 -fmt 'w d mmm yyyy'

which produces:

"Peter","Sun 20 Jan 2000
"Jane","Tue 12 Jan 1970"
"Bill","Sat 14 Jan 1971"
"Anna","Sat 27 Jan 1976"

Created with the Personal Edition of HelpNDoc: Easily create CHM Help documents