Date (Unix command): Difference between revisions

Content deleted Content added
References: Category:Standard Unix programs
m modify subheading redirect
Tags: Redirect target changed Visual edit
 
(30 intermediate revisions by 10 users not shown)
Line 1:
#REDIRECT [[System time#Retrieving system time]]
The '''date''' command outputs the current date and 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>{{cite web |last=Kerrisk |first=Michael |date=Feb 2, 2025 |title=date(1) — Linux manual page |url=https://man7.org/linux/man-pages/man3/date.1.html |access-date=Mar 20, 2025 |website=man7.org |publisher=}}</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 |publisher=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.
 
*-u or --UTC displays [[Universal time|Greenwich Mean Time]]
==References==
{{reflist}}
[[Category:Standard Unix programs]]