Previous Table of Contents Next


Module 30
date

DESCRIPTION

The date command displays the date and time. The super-user (system administrator) can use the date command to change the system's date and time. Any user can use the date command to display the date and time in a standard default format or in a formatted output.

COMMAND FORMAT

Following is the general format of the date command.

     date [ -a[-]sss.fff ] [ -u ][mmdd]hhmm
     date [ -a[-]sss.fff ] [ -u ][ mmddhhmmcc[yy] ]
     date [ -u ] [ +format ]

BSD (Berkeley)
date [ -n ] [ -u ] [ yymmddhhmm.ss] ]
Some BSD systems support the format function of the date command. Check your system's User Reference Manual.

Options

The following list describes the options that may be used to control how date functions.

-a[-]sss.fff Adjust the time by plus or minus ([-]) sss seconds and fff fractions of a second. The systems clock will speed up or slow down until it has slowly adjusted by the specified time of sss.fff. This option is not supported on all systems.
-u Display the date in GMT (Universal time). The system's actual time is set in GMT. The date command performs the necessary conversion to display the date in your current time zone, based on the TZ environment variable. The -u option can also be used to set the time in GMT.
mmddhhmm[cc]yy Change the date and time to the new date and time specified. The century (cc) is not required. The first mm specifies the month, dd the day, hh the hour (24-hour base), the second mm the minutes, and yy specifies the year.
+format Special format strings used to retrieve the date and time in formatted output. See the following format descriptors.

BSD (Berkeley)
yymmddhhmm[.ss] Change the date and time to the new date and time specified. The yy specifies the year, the first mm the month, dd the day, hh the hour (24- hour base), and the second mm the minutes. If you include the .ss then the seconds are set appropriately.
-n If timed, the network time daemon, is running, date sets the time globally on all systems on the local network unless you specify the -n option. The timed command synchronizes the clocks of machines in a local area network.

Format Descriptors

The following is a list of format descriptors. Each descriptor must be preceded by a % character. To display a % character enter %%.

Date format descriptors:

%A The full weekday (Sunday-Saturday)
%a The abbreviated weekday (Sun - Sat)
%B The full month name (January-December)
%b The same as %h
%c The country specific date and time format
%D The date (mm/dd/yy)
%d The day of the month (01 - 31)
%e The day of the month ( 1-31; single digits are preceded by blanks)
%h The abbreviated month (Jan - Dec)
%j The julian date, day of the year (001 to 365)
%m The month of the year (01 - 12)
%U The week number of year (00-53; Sunday is first day of week)
%W The week number of year (00-53; Monday is first day of week)
%w The day of the week (0=Sunday - 6=Saturday)
%X The country specific date format
%Y The year in century format(1990)
%y The current year (00 - 99)

Time format descriptors:

%H The hours (00 - 24)
%I The hours (00 - 12)
%M The minutes (00 - 59)
%p The string containing ante or post meridian indicator (defaults are AM or PM)
%r The time (HH:MM:SS AM/PM)
%S The seconds (00 - 59)
%T The time (HH:MM:SS)
%x The country specific time format
%Z Timezone name

Output format characters:

%n Display a new-line
%t Display a tab
%% Display a percent sign (%)

BSD (Berkeley)
Most BSD systems do not support any format descriptors.

DIAGNOSTICS & BUGS

The following list describes possible error messages you may receive from date.

no permissions You tried to change the date and you are not the super-user.
bad conversion Syntax error in new date or time specification
bad format character Syntax error in the format string

RELATED FILES

The date command writes to the standard output.

APPLICATION

The date utility can be used to change the date or display the date and time. It can produce variable formatted output. If the date is needed in an echo command, you can use the date command to perform most echo command functions. It is often used in shell programming to provide checks, filenames, and information pertaining to the date or time.

TYPICAL OPERATION

In this activity you use date to display the current date and time and then display a formatted date and time.

1.  Type date and press Return. Notice the standard format that date uses to return the information.
        cj> date
        Tue Dec 13 20:23:40 CST 1988

System V
2.  Type the following and press Return. Notice that date can "echo" other information.
        cj> date +"It is %T%ton%t%D"
        It is 20:27:12    on    12/13/88

NOTE:  
It is advisable to enclose all of the date arguments in single quotes to prevent the shell from interpreting the format string. If you use shell variables in the format string then use double quotes in place of single quotes.



3.  Turn to Module 93 (SV), Module 156 (BSD) to continue the learning sequence.
Previous Table of Contents Next