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.[1] Flags such as -d (or -v[2]), 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.[3][4] It can also be used to convert between date formats and/or time zones.[5]
In the base POSIX specification, its only function is to output the current system time. It accepts two optional command-line arguments:[6]
-uselects the UTC/GMT timezone instead of that specified by the environment variableTZor 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,[7][8] 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.[6]
The exit status of the program is 0 on success and any positive value on failure; individual implementations may specify further meaning.[6][9][10][11]
GNU
[edit]The version in GNU coreutils adds the following:[12]
- To set the number of seconds,
.followed by a two-digit number may be appended to the other digits. - A variety of command-line options:
-sor--set=, followed a description, may be used to explicitly set the system time--utcor--universalmay be specified instead of-uto input or output UTC- Specifying the timestamp(s) to process instead of the current system time:
-dor--date=, followed by a description-for--file=, followed by a path to a file containing a description on each line-ror--reference=, followed by a path to a file, to use its modification time
- Adjusting the output format:
--debugrequests additional information to assist in debugging- Predefined timestamp formats:
-Ior--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)-Ror--rfc-emailto 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"
- Alternative information:
--helprequests documentation--resolutionqueries how much precision the timestamps have--versionqueries the program's version number and related information
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.[16]
AIX
[edit]The version on IBM AIX instead adds the following flags:[10]
-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.-ndisables updating other systems on the same LAN that have time synchronization with it.
OpenBSD
[edit]The version on OpenBSD also supports -a (using the adjtime function), as well as the following other flags:[11]
-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 output
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
[edit]The version on FreeBSD supports the following flags:[2]
- (
-dwas previously used to set the flag for daylight saving time) -f, like OpenBSD-I, like GNU-j, like OpenBSD-nis obsolete and ignored-Ris like GNU, though referencing RFC 2822-ris 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- (
-twas 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
References
[edit]- ↑ Nemeth, Evi; Snyder, Garth; Hein, Trent; Whaley, Ben (2011). UNIX and Linux System Administration Handbook (4th ed.). New York: Prentice Hall. pp. 45, 398. ISBN 978-0131-48005-6. Google Books 0SIdBAAAQBAJ.
- 1 2 "date(1) - display or set date and time". General Commands Manual. FreeBSD 15.1. The FreeBSD Project. 10 November 2025.
- ↑ "Formatting and Displaying Dates with Bash Scripts in Linux". The Shell Scripting Guide: From Basics to Advanced Concepts. Vancouver, BC: Squash Labs Inc. 22 October 2023. Archived from the original on 2025-05-30.
- ↑ Halpin, Joe (2003–2005) [Archive-name: unix-faq/shell/sh; Posting-Frequency: monthly; Version: $Id: cus-faq.html,v 1.11 2005/09/01 17:39:36 jhalpin Exp $; Copyright (c) 2003 Joe Halpin]. "comp.unix.shell FAQ - Answers to Frequently Asked Questions : 6. How do I do date arithmetic?". Newsgroup: comp.unix.shell. Archived from the original on 2009-09-06 – via cfajohnson.com.
- ↑ "GNU Core Utilities Frequently Asked Questions : 25 The date command is not working right". Archived from the original on 2026-10-23.
- 1 2 3 "date — write the date and time". Shell & Utilities. The Open Group Base Specifications Issue 8 / IEEE Std 1003.1-2024.
- ↑ "Codes : [XSI] X/Open System Interfaces". The Open Group Base Specifications Issue 8 / IEEE Std 1003.1-2024.
- ↑ "3. Definitions : 3.424 XSI". The Open Group Base Specifications Issue 8 / IEEE Std 1003.1-2024.
- ↑ "Designing Scripts for Cross-Platform Deployment : date". Shell Scripting Primer. Documentation Archive. Apple Inc. 10 March 2014.
- 1 2 "date Command". AIX 7.3.0. IBM Documentation. 15 August 2026.
- 1 2 "date(1) - display or set date and time". OpenBSD manual pages. 29 April 2021.
- ↑ "date(1) - print or set the system date and time". GNU coreutils 9.11. April 2026. Retrieved 2026-11-25 – via man7.org.
- ↑ Bruneau, Guy (12 November 2010). "Scripting with Unix Date". InfoSec Diary Blog Archive. SANS Internet Storm Center.
- ↑ Yuan, Kai (2020–2024). "date Command in Linux". Baeldung on Linux. Retrieved 2026-11-26.
- ↑ Thuermann, Urs (3 December 2012). "Re: time zone and UTC issue". debian-user@lists.debian.org (Mailing list). ygf624jkmyo.fsf@janus.isnogud.escape.de.
- ↑ "11.15 Limitations of Usual Tools : date". 11 Portable Shell Programming. Manual for GNU Autoconf (version 2.69). 24 April 2012.