How many times have you written a shell script that needed to add (say) three days to the current date? This kind of thing came up for me all the time, and it's much harder than it looks (leap years, variable days in a month, etc.). In the late eighties I wrote a yacc-based tool that did most kinds of reasonable math with dates, and it was meant to be used from a shell script:
Today I finally bundled it all up, got it working correctly with flex (the lexer) and bison (the GNU parser), and wrote a web page for it. Distributed in source form.$ datemath today + 5 06/23/2003 $ datemath 12/25/2003 - today 188 $ datemath today + 5 weeks 07/25/2003
Posted by Steve at June 20, 2003 11:18 PM
| TrackBack
But surely GNU date already does this? date --date '3 days ago',
date --date '1 month' (i.e. hence) etc. A GNU extension, I suppose,
so doesn't help on "Old Unix"?
GNU date does some of this, but not all of it (doesn't seem to allow finding the number of days between two dates, among other things), but in any case this was written in an age long before GNU date was around.
Posted by: Steve Friedl on June 21, 2003 06:11 AM