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

echo "`date +%s` - `date --date='3 Jan' +s%s` / ( 60*60*14)" | bc

a little bit less of "$((" ... 
but i don't know a better way

-- 
      _
      |            
YoYo () Siska      
========================
http://www.ksp.sk/


--
[email protected] mailing list

Reply via email to