#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 current or specified date and time and can also set the current system time.
{{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=Apr 27, 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 | date= |title= |url=https://man7.org/linux/man-pages/man5/utmp.5.html |website=man7.org | title=utmp(5) — Linux manual page |date=2024-09-1|___location= |publisher= |access-date=April 27, 2025}}</ref>
==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]]
|