🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

date Command

Beginner System Information man(1)

Display or set the system date and time

👁 11 views 📅 Updated: Mar 15, 2026
SYNTAX
date [OPTION]... [+FORMAT]

What Does date Do?

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.

Options & Flags

OptionDescriptionExample
+FORMAT Custom output format date "+%Y-%m-%d %H:%M:%S"
-d Display specified date (not current) date -d "yesterday"
-u Display UTC time date -u
-s Set the system date/time sudo date -s "2024-01-15 14:30:00"
-R RFC 2822 format (for email) date -R
-I ISO 8601 format date -Iseconds
+%s Unix timestamp (seconds since epoch) date +%s

Practical Examples

#1 Current date and time

Shows the current date and time.
$ date
Output: Mon Jan 15 14:30:00 UTC 2024

#2 Custom format

Formats date as YYYY-MM-DD HH:MM:SS.
$ date "+%Y-%m-%d %H:%M:%S"
Output: 2024-01-15 14:30:00

#3 Unix timestamp

Shows seconds since January 1, 1970 (epoch).
$ date +%s
Output: 1705327800

#4 Yesterday date

Calculates and formats yesterday date.
$ date -d "yesterday" +%Y-%m-%d
Output: 2024-01-14

#5 Date arithmetic

Calculates date 3 days in the future.
$ date -d "+3 days" +%Y-%m-%d
Output: 2024-01-18

#6 Backup filename

Creates a timestamped backup filename.
$ tar czf "backup_$(date +%Y%m%d_%H%M%S).tar.gz" /data/

#7 ISO 8601 format

Shows date in ISO 8601 format with timezone.
$ date -Iseconds
Output: 2024-01-15T14:30:00+00:00

#8 Convert timestamp

Converts Unix timestamp to human-readable date.
$ date -d @1705327800
Output: Mon Jan 15 14:30:00 UTC 2024

Tips & Best Practices

Common format codes: %Y=year, %m=month, %d=day, %H=hour, %M=minute, %S=second, %s=epoch, %A=weekday name, %B=month name.
Date math with -d: date -d supports: yesterday, tomorrow, last friday, 2 weeks ago, +3 months, next year, etc.
Setting time: On systemd systems, use timedatectl set-time instead of date -s. Ensure NTP is disabled first.

Frequently Asked Questions

How do I get a timestamp for filenames?
Use date +%Y%m%d_%H%M%S for something like 20240115_143000. For just the date: date +%Y-%m-%d.
How do I get yesterday date?
date -d "yesterday" +%Y-%m-%d. Other options: -d "2 days ago", -d "last monday", -d "+1 week".
How do I convert a Unix timestamp?
date -d @TIMESTAMP. Example: date -d @1705327800 converts epoch seconds to readable date.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →