Hihi,

I needed just now to count today how many days have elapsed since the 3rd of January. Rather than reach for a calendar and count days arduously, I figured this was a task very suited to a computer. I'm sure, however, my solution took me longer than the manual one would have - can anyone suggest a better one?

I know that `date` can provide the date in seconds since the epoc, and after a couple of readings of the `man` page I discovered that `info date` is FAR more comprehendible.

$ date  +%s
1107845877
$ date  +%s -d '3 Jan'
1104710400

Ok... so a Google for Bash mathematics turns up <http://en.wikipedia.org/wiki/Bash#Integer_mathematics>, and after some experimentation I came up with:

$ echo $(( $((`date +%s` - `date --date='3 Jan' +%s`)) / 60 / 60 / 24 ))

That's a pretty unmemorable command, however, and next time I want to work out how many days have elapsed since $ARBITRARY_DATE I'll have to look up how to do it again. Can anyone suggest a more concise command line, please?

I'm sure I'm missing something obvious like the bash-builtin command `dayssince` or `emerge cal-tools` - what I really want to do is type `how many days since 3rd January` and get the answer. Gold stars will not be awarded for telling me to make my own alias in .bash_profile.

Stroller.

--
[email protected] mailing list



Reply via email to