On Tue, Feb 08, 2005 at 07:14:05AM +0000, Stroller wrote:
> 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?

<snip>

> 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 
> ))

<snip>

why not make the commands into a script? something like

#!/bin/bash
# days_elapsed.sh
echo $(( $((`date +%s` - `date --date="${1}" +%s`)) / 60 / 60 / 24 ))

$ days_elapsed.sh "4 Jan 1990"
5514

Or you could probably find a seperate program to do this GNU Calendar
for example but if you can do something just as well with a shell script
why bother?

Cheers

Joel

--
[email protected] mailing list

Reply via email to