Linux Command: date
Display or set the system date and time
date displays or sets the system date and time. It supports extensive formatting options for creating timestamps, date calculations, and converting between date formats. date is essential for log timestamps, backup naming, cron job reporting, and any script that needs to work with dates. It supports format strings with + prefix for custom output. date can perform date arithmetic with the -d flag, allowing you to calculate relative dates like "yesterday", "next friday", "2 hours ago", and more.
Syntax
date [OPTION]... [+FORMAT]Key Options
+FORMATโ Custom output format-dโ Display specified date (not current)-uโ Display UTC time-sโ Set the system date/time-Rโ RFC 2822 format (for email)-Iโ ISO 8601 format
Examples
Current date and time
dateOutput: Mon Jan 15 14:30:00 UTC 2024
Custom format
date "+%Y-%m-%d %H:%M:%S"Output: 2024-01-15 14:30:00
Unix timestamp
date +%sOutput: 1705327800
Pro Tips
- %Y=year, %m=month, %d=day, %H=hour, %M=minute, %S=second, %s=epoch, %A=weekday name, %B=month name.
- date -d supports: yesterday, tomorrow, last friday, 2 weeks ago, +3 months, next year, etc.
- On systemd systems, use timedatectl set-time instead of date -s. Ensure NTP is disabled first.
Learn more: Full date reference โ
Related Resources