date command in Unix | Linux Tutorial

date Command

date command is used to display the current system date and time.

date
Mon Mar 31 16:10:40 IST 2019

This command can be used with different format specifiers as arguments. Each format is preceded by the + symbol, then the % operator, and a single character specifying the format.

date +%m
03

date +%h
Mar

date +"%h %m"
Mar 03

m - to print the month (01 - 12)
h - to print month name
d - to print day of the month (1 - 31)
y - to print last two digit of year
H - to print hours
M - to print minutes
S - to print seconds
D - to print date (mm/dd/yy)
T - to print time (hh:mm:ss)

Comments