This site uses advanced css techniques
Too many times we have needed to do a bit of math on a date -- say, "today + 7 days" -- but in traditional MM/DD/YYYY format this is really tricky (especially in a shell script). A result of this need we built the datemath tool which can perform these functions from the command line or from a shell script. Examples:
$ datemath today + 5 06/23/2003 $ datemath '12/25/2003 - today' 188 $ datemath today + 5 weeks 07/25/2003 when will my machine be up for one year? $ uptime 11:09am up 317 days, 15:38, 7 users, load average: 0.16, 0.04, 0.01 $ datemath today + 365 - 317 10/24/2003
We've been using this for 15 years, and recently got around to porting it and updating for year-2000 compatibility (oops). The port to Bison/flex from yacc/lex was a bit of doing as well.
The expressions accepted by datemath are straightforward and moderately flexible. The grammer is defined to reject most things that don't make any sense (such as adding two dates together), while allowing most things that do.
Dates can be entered in one of three formats:
Keywords are shown here in upper case to make them stand out, but the program doesn't care at all about case, and mixed upper/lower work fine. Remember that parentheses are special to the shell, so they must be quoted.
These can be combined in most combinations that make sense, though we've never gotten too elaborate about making sure that it's completely orthogonal.
In addition to the date expression above (required), a few command-line parameters are supported.
Not all things that makes sense are implemented. For instance, the notation
1/31/2003 + 3 MONTHSdoesn't work because it's not quite clear what it means: 4/31/2003 is not a valid date, so we couldn't find any obvious direction to adjust the date to conform.
The source is delivered as a gzip'd GNU tar archive (do a "save as"):
• datemath.tar.gz - compressed tarball of source
The files inside are:
$ gtar -tzf datemath.tar.gz datemath.c gram.y lex.l util.c jdate.c defs.h Makefile
Note that this package requires GNU flex and bison: those needing to use the older tools may have some troubles. Reports of portability issues are gratefully accepted.
Fri Jun 20 23:01:46 PDT 2003 -- version 2.0.10 -- initial release to website