Table of Contents

date : How to use date command in Linux with examples



man date

       FORMAT controls the output.  Interpreted sequences are:

       %Y     year

       %m     month (01..12)

       %d     day of month (e.g., 01)

       %H     hour (00..23)
       %I     hour (01..12)

       %M     minute (00..59)

       %S     second (00..60)


Example

## 1 day ago
% date -d '1day ago' +%Y%m%d
20151102
%

% date +"%d%m%Y"
03112015
%

% date +"%H:%M"
23:34
%

UNIX timestamp


# date -d "2015-10-1 12:34" +%s
1443702840

unix time → string time

# date --date "@1443702840"
Thu Oct  1 12:34:00 GMT 2015