Date (Unix command)

From Wikipedia, the free encyclopedia

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 scripts to perform automated actions such as calculating the difference between different times, converting times between timezones, reformating timstamps in texts to fit different date presentation requirements and adding versioning information to backup and other files.[1][2]

Option flags

Summarize
Perspective
  • +"date format codes" Alters the output using the specified date conversion codes which are prefaced with at % sign.[3] For POSIX compatibility the format codes correspond to the same format codes recognized by C's strftime() function. Not surprisingly many Unix implementations use this function in their implementation of date.[4]
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.[5] 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.[6]

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.[7]
Summarize
Perspective
  • 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 List of ISO 639 language codes or List of ISO 3166 country codes6 [8]

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.[3]


  • 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 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 (DST). [9]

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.[citation needed] With that in mind both 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.[10][11]

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.[3][12]

References

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.