date is a Unix command for calendar/clock computations and working with timestamps, particularly the system time. It exists in most Unix-like operating systems, and its primary purpose is to print or set the current time.
It can be used in a shell script to format dates when generating filenames. Flags such as -d (or -v), when supported, can be used to perform some time-based calculations, and others can be done through math on the Unix time of each date. It can also be used to convert between date formats and/or time zones.
In the base POSIX specification, its only function is to output the current system time. It accepts two optional command-line arguments:
-u selects the UTC/GMT timezone instead of that specified by the environment variable TZ or the system default.+ is followed by a C-style timestamp format string to specify how to arrange the date and time components in the output. In the POSIX or C locale, this defaults to "%a %b %e %H:%M:%S %Z %Y". The %e specifier was added to the relevant standards to allow the user to specify a format string equivalent to the traditional default.In the X/Open Systems Interfaces (XSI) option that extends POSIX to the Single UNIX Specification, a second mode is added, that sets the system time. This is used when an 8-, 10-, or 12-digit number is specified as a command-line argument. This input is parsed as a 2-digit month, then a 2-digit day, then a 2-digit hour (in the 24-hour clock), then a 2-digit minute, optionally followed by a 2- or 4-digit year (defaulting to that of the current time). This mode also supports the -u flag.
The exit status of the program is 0 on success and any positive value on failure; individual implementations may specify further meaning.
The version in GNU coreutils adds the following:
. followed by a two-digit number may be appended to the other digits.-s or --set=, followed a description, may be used to explicitly set the system time--utc or --universal may be specified instead of -u to input or output UTC-d or --date=, followed by a description
@ followed by a number to specify Unix time, or some other absolute or relative date/time-f or --file=, followed by a path to a file containing a description on each line-r or --reference=, followed by a path to a file, to use its modification time--debug requests additional information to assist in debugging-I or --iso-8601(=) to request ISO 8601 compliance, optionally followed by the level of precision to use: "date" (default), "hours", "minutes", "seconds", or "ns" (this includes the time zone's UTC offset when the time is included)-R or --rfc-email to request RFC 5322 compliance--rfc-3339=, followed by the desired level of precision ("date", "seconds", or "ns"), to request RFC 3339 compliance, separating the date and time with a space instead of "T"--help requests documentation--resolution queries how much precision the timestamps have--version queries the program's version number and related informationThe GNU version also adds additional specifiers that can be used in the timestamp format string; some systems that don't support them instead output them as-is without error.
The version on IBM AIX instead adds the following flags:
-a, followed by a positive or negative number of seconds, adjusts the system clock by speeding it up or slowing it down until the resulting clock drift matches the amount of time specified.-n disables updating other systems on the same LAN that have time synchronization with it.The version on OpenBSD also supports -a (using the adjtime function), as well as the following other flags:
-f, followed by a timestamp format string used for parsing input-j, to perform input and output without modifying the system time-r, followed by a Unix time in seconds, specifies the timestamp to output-z, followed by a timezone, specifies which one to use when producing outputAdditionally, it is compliant with the base POSIX specification, but only partially with the XSI option: an 8-digit timestamp is parsed the same way, but longer lengths are different, because the 2- or 4-digit year is at the start rather than the end. It also allows omitting month, month+day, or month+day+hour, only requiring the minutes to be specified. The suffix '.SS' for seconds is supported like GNU.
Any changes to the system time are tracked in /var/log/wtmp and /var/log/messages.
The version on FreeBSD supports the following flags:
-d was previously used to set the flag for daylight saving time)-f, like OpenBSD-I, like GNU-j, like OpenBSD-n is obsolete and ignored-R is like GNU, though referencing RFC 2822-r is supported in both the GNU (mtime of file) and OpenBSD (seconds since Unix epoch) senses; the latter allows the number to be specified as decimal, hex, or octal-t was previously used to set a sign-reversed time zone offset)-u, as per POSIX-v, followed by an optional sign, and then either a number and a unit of time, or the name of a month or weekday, to set or shift the date to be output; this option may be repeated to apply multiple changes sequentially-z, like OpenBSD