#REDIRECT [[System time#Retrieving system time]]
<!-- Please do not remove or change this AfD message until the discussion has been closed. -->
<!-- The nomination page for this article already existed when this tag was added. If this was because the article had been nominated for deletion before, and you wish to renominate it, please replace "page=Date (Unix command)" with "page=Date (Unix command) (2nd nomination)" below before proceeding with the nomination.
-->{{Article for deletion/dated|page=Date (Unix command)|timestamp=20250426150027|year=2025|month=April|day=26|substed=yes}}
<!-- Once discussion is closed, please place on talk page: {{Old AfD multi|page=Date (Unix command)|date=26 April 2025|result='''keep'''}} -->
<!-- End of AfD message, feel free to edit beyond this point -->
The date command outputs the current or specified date and time and can also set the current system time. While available as a command line utility it is also used in [[Shell script|shell scripts]] to perform automated actions such as calculating the difference between different times, converting times between timezones, reformating timstamps in texts to fit different [[List of date formats by country|date presentation requirements]] and adding versioning information to backup and other files.<ref>{{cite book|last1=Nemeth|first1=Evi |last2=Snyder| first2=Garth |last3=Hein| first3=Trent | last4=Whaley| first4=Ben| title=UNIX and Linux System Administration Handbook| edition=4th | publisher=Prentice Hall|___location=New York|year=2011| isbn=978-0131-48005-6| pages=45,398}}</ref><ref>{{cite web| author=<!-- not stated --> | title=Formatting and Displaying Dates with Bash Scripts in Linux|date=Oct 22, 2023| url=https://www.squash.io/formatting-and-displaying-dates-with-bash-scripts-in-linux/ | website=www.squash.io| publisher=Squash Labs Inc|___location=Vancouver BC| access-date=Apr 28, 2025}}</ref>
{{Rcat shell|
==Option flags==
{{R to related topic}}
}}
*+"''date format codes"'' Alters the output using the specified date conversion codes which are prefaced with at % sign.<ref name=Kerrisk>{{cite web |last=Kerrisk |first=Michael |date=Feb 2, 2025 |title=date(1) — Linux manual page |url=https://man7.org/linux/man-pages/man1/date.1.html |access-date=Mar 20, 2025 |website=man7.org |publisher=}}</ref> For [[POSIX]] compatibility the format codes correspond to the same format codes recognized by [[C (programming language)|C]]'s [[Strftime|strftime()]] function. Not surprisingly many Unix implementations use this function in their implementation of '''date'''.<ref>{{cite web |author=<!-- not stated --> |year=2025 |title=IEEE and The Open Group Base Specifications Issue 8>3. Utilities>date |url=https://pubs.opengroup.org/onlinepubs/9799919799/ |website=pub.opengroup.org |___location= |publisher=The Open Group |access-date=Apr 27, 2025}}</ref>
date +"Today is day %j of the year %Y and it’s a %A"
Output: Today is day 078 of the year 2025 and it’s a Wednesday
*-d "''datestring''" or --date=''"datestring"'' Displays the quoted date. Can be used with the + flag. Date strings consist of ''calendar date items'' which express day month and year, ''and time of day items'' which express hour:minute:second''.'' Either item group is optional and they may appear in either order.<ref>{{cite web |author=<!-- not stated --> |title=Date input formats |url= https://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.htmlwebsite=gnu.org |publisher=gnu.org |access-date=Mar 20, 2025}} </ref> Times and dates can be adjusted using ''relative item'' expressions such as + or - ''time unit'' as well as keywords such as ''now, yesterday, tomorrow, previous, next, first and last.<ref>{{cite web |author=<!-- not stated --> |title=Relative items in date strings |url= https://www.gnu.org/software/coreutils/manual/html_node/Relative-items-in-date-strings.html|website=gnu.org |access-date=Mar 20, 2025}}</ref>
''Examples:''
date -d "''Jan 14, 2026 4:33 PM"''
date --date="17:51:02 22/12/2020"
date -d "next Tuesday +2 years -8 hours + 3 days"
*-f ''filename'' or --file''=filename'' where the referenced file contains one of more date strings on separate lines which are converted either to the default date format or the format specified by the '''+''' flag. Incompatible with the '''-d''' flag.
*-r or --reference=''filename ''- outputs the last modification time of the file
*-s or --set="''datestring"'' sets the current date and time to the value of ''datestring.'' Requires an account with admin privilege.<ref>{{cite book|last1=Glass |first1=Graham | last2=King| first2=Ables|date=2006 |title=Linux for Programmers and Users |___location=Upper Saddle River, NJ |publisher=Pearson Prentice Hall|page=44|isbn=978-0131-857483}} </ref>
*-u or --UTC displays [[Universal time|Greenwich Mean Time]]
==Related environment variables==
*LC_TIME - changes the language and default order and format in which the date is presented
export LC_TIME=fr_CA.utf8
The value corresponds assigned to LC_TIME refers to files found in /usr/share/i18/locale. The file name is usually of the form languageCode_countryCode where the codes are the two character ISO codes for [[language|List of ISO 639 language codes]] or [[country|List of ISO 3166 country codes6]] <ref>{{cite web| author=<!-- not stated --> |title=Locale Environment Variables: Locale Names |url=https://www.gnu.org/software/gettext/manual/html_node/Locale-Names.html|website=www.gnu.org |publisher=gnu.org |access-date=Mar 20, 2025}}</ref>
It is also possible to change the date presentation format by setting the environment variables LANG or LC_ALL however these will also change other presentation formats such as LC_MESSAGE (command error messages) and LC_MONETARY which many not be desirable.<ref name=Kerrisk></ref>
*TZ - Alters the output of the command to reflect the designated time zone.
export TZ=Africa/Nairobi
The directory /usr/share/zoneinfo contains a large group of [[tz database| timezone database files|]] files describing both current and historical definitions of local times to facilitate the correct reproduction and translation of time information from one time zone and era to another. The files keep track of the offset from Greenwich Mean Time as well as when seasonal adjustments have been scheduled to take place such as the transition to and from [[Daylight saving time|Daylight Saving Time]] (DST). <ref>{{cite book |last=Ward |first=Brian |date=April 19, 2021 |title=How Linux Works, 3rd Edition |publisher=No Starch Press |section=7.5.1 |isbn=978-1718-500402}} </ref>
==Security==
The integrity of system timestamps are extremely important for fraud detection by keeping track of precisely when financial transactions and other changes occur. By resetting the clock it is possible to misrepresent sequences of events.{{cn|date=April 2025}} With that in mind both [[Berkeley Software Distribution| BSD]] and [[GNU]] based Unix systems log both the before and after times when the clock is reset, including by the date command, in the [[utmp]] file.<ref>{{cite web| author=<!-- not stated --> | url=https://www.unix.com/man_page/bsd/5/utmp/https://www.unix.com/man_page/bsd/5/utmp/ | title=bsd man page for utmp| publisher=Unix Linux Community| website=community.unix.com | date=Nov 27, 1996 | access-date=April 27, 2025 }}</ref><ref> {{cite web | author=<!-- not stated --> | editor-last=Kerrisk| editor-first=Michael |url=https://man7.org/linux/man-pages/man5/utmp.5.html |website=man7.org | title=utmp(5) — Linux manual page |date=2024-09-01|___location= |publisher= |access-date=April 27, 2025}}</ref>
==Implementations in Other OS Environments==
===Multics===
[[Multics]] was a multi-user operating system from [[Honeywell]] that was a major inspiration for Unix. It had the following time and date related active functions which could be entered either directly on the command line or embedded in other commands using square brackets: '''date''', '''time''', '''date_time''', '''year''', '''month''' (number), '''month_name''', '''day '''(number), '''day_name''', '''hour''', '''minute'''.<ref>{{cite web| author=<!-- not stated --> | title=Multics Pocket Guide: Commands and Active Functions| date=April 1980 | url=https://multicians.org/multics-commands.html | website=www.bitsavers.org | publisher=Honeywelll|access-date=May 1, 2025}}</ref>
===MPE===
[[MPE]] was an operating system that ran on HP 1000 and 3000 minicomputers. The command to display the date and time were '''SHOWTIME''' and '''SHOWCLOCK'''. The latter command added the time zone offset from GMT and a "correction" factor reflecting previous manual adjustments due to [[Clock drift|clock drift]]. Neither had any options.<ref>{{cite web |author=<!-- not stated --> | title=MPE/iX Commands Reference manual Volume I: SHOWCLOCK | url=http://www.3kranger.com/HP3000/mpeix/doc3k/B3265090819.11741/200.htm | publisher=Hewlett Packard | access-date=May 1, 2025}}</ref><ref>{{cite web | author=<!-- not stated --> | title=MPE/iX Commands Reference manual Volume I: SHOWTIME | url=http://www.3kranger.com/HP3000/mpeix/doc3k/B3265090819.11741/211.htm
| publisher=Hewlett Packard | access-date=May 1, 2025}}</ref>
To reset both values '''SETCLOCK''' had named parameters '''DATE'''=''mm/dd/yy[yy]'' , '''TIME'''=''hh:mm[:ss]'' and '''CORRECTION'''=''offset in seconds''. and '''TIMEZONE'''. Two additional parameters '''NOW''' or '''GRADUAL''' indicated either the change should be immediate or that the system clock should either speed up or slow down to reach the specified new time. <ref>{{cite web |author=<!-- not stated --> | title=MPE/iX Commands Reference manual Volume I: SETTIME | url=http://www.3kranger.com/HP3000/mpeix/doc3k/B3265090819.11741/191.htm
| publisher=Hewlett Packard | access-date=May 1, 2025}}</ref>
{{Expand section|date=May 2025|further OS/shell examples}}
==History==
David McKenzie is the author of the Linux version of date. The date command has been part of Unix since AT&T's original Version 1.<ref name=Kerrisk /><ref>{{cite web |author=<!-- not stated --> |date=September 10, 2024 |title=FreeBSD Manual Pages |url=https://man.freebsd.org/cgi/man.cgi?date |website=man.freebsd.org |access-date=April 1, 2025}}</ref>
==References==
{{reflist}}
[[Category:Standard Unix programs]]
|