Database Reference
In-Depth Information
--warn
Warn about bad dates. (This option can produce spurious warnings if the dates
have two-digit years and you don't specify
--add-century
, because leap-year testing
won't always be accurate in that case.)
I won't show the code for
cvt_date.pl
here (most of it is taken up with processing
command-line options), but you can examine the source for yourself if you like. As an
example of how
cvt_date.pl
works, suppose that you have a file
newdata.txt
with the
following contents:
name1 01/01/99 38
name2 12/31/00 40
name3 02/28/13 42
name4 01/02/18 44
Running the file through
cvt_date.pl
with options indicating that the dates are in US
format and that the century should be added produces this result:
%
cvt_date.pl --iformat=us --add-century newdata.txt
name1 1999-01-01 38
name2 2000-12-31 40
name3 2013-02-28 42
name4 2018-01-02 44
To produce dates in British format instead with no year conversion, do this:
%
cvt_date.pl --iformat=us --oformat=br newdata.txt
name1 01-01-99 38
name2 31-12-00 40
name3 28-02-13 42
name4 02-01-18 44
cvt_date.pl
has no knowledge of the meaning of each data column, of course. If you have
a nondate column with values that match the pattern, it rewrites that column, too. To
deal with that, specify a
--columns
option to limit the columns that
cvt_date.pl
converts.
isoize_date.pl
and
cvt_date.pl
both operate on dates written in all-numeric formats. But
dates in datafiles often are written differently, and it may be necessary to write a special-
purpose script to process them. Suppose an input file contains dates in the following
format (these represent the dates on which US states were admitted to the Union):
Delaware Dec. 7, 1787
Pennsylvania Dec 12, 1787
New Jersey Dec. 18, 1787
Georgia Jan. 2, 1788
Connecticut Jan. 9, 1788
Massachusetts Feb. 6, 1788
…
The dates consist of a three-character month abbreviation (possibly followed by a pe‐
riod), a numeric day of the month, a comma, and a numeric year. To import this file