slicing the date

Rodney R. Green rgreen at druhi.ATT.COM
Fri Mar 31 02:04:26 AEST 1989


in article <216000010 at s.cs.uiuc.edu>, carroll at s.cs.uiuc.edu says:
> Nf-ID: #N:s.cs.uiuc.edu:216000010:000:703
> Nf-From: s.cs.uiuc.edu!carroll    Mar 27 15:34:00 1989
> 
>                 .... The question is, how can I cut up the output of
> date to put the hours, minutes, and seconds into seperate variables? Thanks!
> 
> Alan M. Carroll          "And then you say,
> carroll at s.cs.uiuc.edu     We have the Moon, so now the Stars..."  - YES
> CS Grad / U of Ill @ Urbana    ...{ucbvax,pur-ee,convex}!s.cs.uiuc.edu!carroll

The date command has a parameter with which you can specify the format of the
output.  The following three commands will output the hours, minutes, and
seconds respectively:
date +%H
date +%M
date +%S

Of course, setting them separately can result in skew (suppose the hour
changes between the time you set hours and minutes).  You can get output
of the form HH MM SS with the following command.
date +"%H %M %S"
and then cut it up to get the pieces you want.  

See the manual page for date(1) for the complete description of
formatting from date.

Rodney Green
rgreen at druhi.att.com           ...!att!druhi!rgreen
AT&T Bell Laboratories     Denver, CO



More information about the Comp.unix.questions mailing list