Date (Unix command)

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:

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.

GNU

The version in GNU coreutils adds the following:

The 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.

AIX

The version on IBM AIX instead adds the following flags:

OpenBSD

The version on OpenBSD also supports -a (using the adjtime function), as well as the following other flags:

Additionally, 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.

FreeBSD

The version on FreeBSD supports the following flags: