Date + % Y % m % d-date = "-1 day"
Date usage: Date [Option]… [+ Format]
Date [-u | -- UTC | -- Universal] [mmddhhmm [[CC] YY] [. SS]
Date can be used to display or set the date and time of the system.
1. In terms of display, users can set the format to be displayed. The format is set to a plus sign followed by several tags. The available tag list is as follows: %: Print %
% N: Next row
% T: Skip
% H: hour (00 .. 23)
% I: hour (01 .. 12)
% K: hour (0 .. 23)
% L: hour (1 .. 12)
% M: minute (00 .. 59)
% P: displays local am or PM
% R: direct display time (in 12-hour format: hh: mm: ss [AP] m)
% S: the number of seconds since January 1, 1970 00:00:00 UTC till now
% S: seconds (00 .. 61)
% T: direct display time (in 24-hour format)
% X: equivalent to % H: % m: % s
% Z: Display Time Zone % A: day of the week (Sun .. SAT)
% A: The day of the week (Sunday .. Saturday)
% B: Month (Jan .. dec)
% B: Month (January... December)
% C: Display date and time directly
% D: Day (01 .. 31)
% D: Display date directly (mm/DD/yy)
% H: Same as % B
% J: The day of the year (001 .. 366)
% M: Month (01 .. 12)
% U: Week (00 .. 53) of the year (the first day of the week on Sunday)
% W: The day of the week (0 .. 6)
% W: Week (00 .. 53) of the Year (Monday is the first day of the week)
% X: Display date directly (mm/DD/yy)
% Y: last two digits of the Year (00.99)
% Y: full year (0000 .. 9999)
2. Set the time
Date-S // set the current time. Only the root permission can be set. Others can only be viewed.
Date-s 20080523 // set to 20080523, so that the specific time is set to null 00:00:00
Date-s 01:01:01 // set the specific time and do not change the date
Date-s "01:01:01" // you can set all the time
Date-s "01:01:01 20080523" // you can set all the time
Date-s "01:01:01" // you can set all the time
Date-s "20080523 01:01:01" // you can set all the time
3. addition and subtraction
Date + % Y % m % d // display the day before yesterday
Date + % Y % m % d-date = "+ 1 day" // display the date of the previous day
Date + % Y % m % d-date = "-1 day" // display the date of the next day
Date + % Y % m % d-date = "-1 month" // display the date of the previous month
Date + % Y % m % d-date = "+ 1 month" // display the date of the next month
Date + % Y % m % d-date = "-1 year" // display the date of the previous year
Date + % Y % m % d-date = "+ 1 year" // display the date of the next year
4. Use in shell scripts
Monthbacktwo = 'date + % Y % m % d-date = "-1 month "'
From: http://www.asdtiang.org/2012/06/07/linux-date-date-of-addition-and-subtraction/