Jump to content

Date (Unix command)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Northernhenge (talk | contribs) at 20:54, 20 March 2025 (References: Category:Standard Unix programs). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The date command outputs the current date and time.  

Option flags

  • +”date format codes” Alters the output using the specified date conversion codes which are prefaced with at % sign. [1] 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.[2] 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.[3]

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.

References

  1. ^ Kerrisk, Michael (Feb 2, 2025). "date(1) — Linux manual page". man7.org. Retrieved Mar 20, 2025.
  2. ^ "Date input formats". gnu.org. Retrieved Mar 20, 2025.
  3. ^ "Relative items in date strings". gnu.org. gnu.org. Retrieved Mar 20, 2025.