DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

date(C)


date -- print and set the date

Syntax

date [ -u ] [ +format ]

date [ -u ] [ MMDDhhmm[YY] | -t [CC]YYMMDDhhmm[.SS] ]

Description

If no argument is given, or if the output format is specified following +, the current date and time are printed as defined by the locale. Otherwise, you may set the system date and time if you are root.

date normally performs its calculations taking care of the conversion to and from local standard and daylight time.

The -u option, if specified, causes operations to be performed as if the current time zone is Greenwich Mean Time (the environment variable TZ is set to GMT0).

When setting the date and time, you can specify it in the form MMDDhhmm[YY], where:


MM
month (01-12)

DD
day of month (01-31)

hh
hour in the 24-hour system (00-23)

mm
minute (00-59)

YY
last 2 digits of the year (optional)
If you use the -t option, you can also optionally specify the century and the second using the form [CC]YYMMDDhhmm[.SS] where:

CC
century (00-99)

SS
second (00-59)

For example, date 10080045 sets the date to Oct 8, and the time to 12:45 AM, if the local language is set to English. The current year is taken by default if no year is specified.

If the argument begins with +, the output of date is under the control of the user. The format for the output is similar to that of the first argument to printf(S). All output fields are of fixed size (zero padded if necessary). Each field descriptor begins with a percent sign ``%'' and is replaced in the output by its corresponding value. A single percent sign may be output if it is quoted with another percent sign, that is, by specifying ``%%''. All other characters are copied to the output without change. The string is always terminated with a newline character. Extra newlines may be produced using the descriptor ``%n''.

Field descriptors


%%
quoted percent sign

%a
abbreviated weekday, as defined by the locale (for example, Sun to Sat)

%A
full weekday name, as defined by the locale

%b
abbreviated month name, as defined by the locale

%B
full month name, as defined by the locale

%c
current date and time, as defined by the locale

%C
century as a decimal number, 00 to 99

%d
day of month, 01 to 31

%D
date as MM/DD/YY

%e
day of month as a decimal number, in range 01 to 31 (in a two digit field with numbers less than 10 preceded by a space character)

%h
abbreviated month, as defined by the locale (for example, Jan to Dec)

%H
hour, 00 to 23

%I
hour (12-hour clock), 01 to 12

%j
day of the year, 001 to 366

%m
month of year, 01 to 12

%M
minute, 00 to 59

%n
inserts a newline character

%p
equivalent of AM or PM for current locale

%r
time in AM/PM notation

%S
second, 00 to 61

%t
inserts a tab character

%T
time as hh:mm:SS (24 hour clock)

%u
week day as a decimal number, with Monday represented by day 1

%U
week number of the year (Sunday as the first day of the week) as a decimal number in the range 00 to 53 (all days in a new year preceding the first Sunday are considered to be in week 0)

%V
week number of the year (Monday as the first day of the week) as a decimal number in the range 01 to 53. If the week containing January 1 has four or more days in the new year, then it is considered week 1; otherwise it is week 53 of the previous year, and the next week is week 1

%w
day of the week, with Sunday represented by 0

%W
week number of the year (Monday as the first day of the week) as a decimal number in the range 00 to 53. (All days in a new year preceding the first Sunday are considered to be in week 0.)

%x
current date, as defined by the locale

%X
current time, as defined by the locale

%y
year (offset from %C) as a decimal number in the range 00 to 99

%Y
year (including century), as decimal numbers

%Z
timezone name, or no characters if no timezone exists

Modified field descriptors

Some field descriptors can be modified by the E and O modifier characters to indicate a different format or specification, as follows:

%Ec
locale's alternative appropriate current date and time representation

%EC
name of the base year (period) in the locale's alternative representation

%Ex
locale's alternative date representation

%EX
locale's alternative time representation

%Ey
offset from %EC (year only) in the locale's alternative representation

%EY
full alternative year representation

%Od
day of month, using locale's alternative numeric symbols

%Oe
day of month, using locale's alternative numeric symbols

%OH
hour (24 hour clock), using locale's alternative numeric symbols

%OI
hour (12 hour clock), using locale's alternative numeric symbols

%Om
month, using locale's alternative numeric symbols

%OM
minutes, using locale's alternative numeric symbols

%OS
seconds, using locale's alternative numeric symbols

%Ou
weekday as a number in the locale's alternative representation (Monday=1)

%OU
week number of the year (Sunday as the first day of the week) using locale's alternative numeric symbols

%OV
week number of the year (Monday as the first day of the week, rules corresponding to %V) using locale's alternative numeric symbols

%Ow
weekday as a number in the locale's alternative representation (Sunday=0)

%OW
week number of the year (Monday as the first day of the week), using locale's alternative numeric symbols

%Oy
year (offset from %C) in alternative representation

Exit values

date returns the following exit values:

0
the date was written successfully

>0
an error occurred

Diagnostics


-? illegal option
The option specified is not known to date.

bad conversion
The date specified is syntactically incorrect.

format conversion error
The format string specified is invalid.

no permission
Only root may change the date.

Examples

The line date '+DATE: %m/%d/%y%nTIME: %H:%M:%S' generates output in the form:
   DATE: 08/01/90
   TIME: 14:45:05

Files


/bin/date
date executable file

See also

locale(M), strftime(S)

Standards conformance

date is conformant with:

ISO/IEC DIS 9945-2:1992, Information technology - Portable Operating System Interface (POSIX) - Part 2: Shell and Utilities (IEEE Std 1003.2-1992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992;
X/Open CAE Specification, Commands and Utilities, Issue 4, Version 2, 1994..


© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003