Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date -d & pulling out hair

Status
Not open for further replies.

Igaduma

Technical User
Nov 23, 2001
322
0
0
BE
hello all,

on a solaris 9 machine there seems to be no date -d function?
how does one do time/date arithmatic in bash ?

I need to have the date '+%H:%M' minus 5 minutes ?


Thanks!
Iga
 
Hi,
I did a man date on my solaris 9 box and it says

FSF Last change: GNU Shell Utilities

It supports the -d option, but I can't find where it is installed on our server.

/usr/bin/date doesn't support it as you pointed out.

Maybe you can find the GNU shell utilities ( which might complement BASH but weren't installed ) and get them installed on your machine.


Here is a csh script to subtact 5 minutes in %H:%M format.
I do it by adding a day - 5 minutes to avoid the if statements with 00:00 - 00:04 becoming 23:55 - 23:59

#! /bin/csh

set h = `date "+%H"`
set m = `date "+%M"`

@ min = ( $h * 60 ) + $m + 1435
@ h = ( $min / 60 ) % 24
@ m = $min % 60

echo "$h $m" | awk '{printf("%2d:%2d\n",$1,$2)'};


I used awk to make sure I could get 2 DIGIT numbers in the display

00:01 instead of 0:1


Someone in my office suggest perl


perl -e '$now = localtime(time-300); printf("%s\n",substr($now,11,5));'


but if you wanted a PERL solution you probably would have asked you question in the PERL forum.





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top