How does Shell specify a date minus one day
This article mainly introduces the relevant knowledge of "how Shell specifies a date minus one day". Xiaobian shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "how Shell specifies a date minus one day" can help you solve the problem.
If you subtract only one day, you can write it directly.
#date -d"yesterday 20150401" +%Y%m%d
If you want to subtract a few days, you can write it like this. If you use negative numbers, you can count forward.
#date -d"10 day ago 2015-04-01" +%Y-%m-%d
Add the specified hour to the specified date
[dc@dc010.tj.momo.com init_env]$ date -d "20150416 12 3 hour" +"%Y%m%d%H"2015041615
Subtracts the specified hour from the specified date
[dc@dc010.tj.momo.com init_env]$ date -d "20150416 12 -1 hour" +"%Y%m%d%H"2015041611
Add the specified minutes to the specified date
[dc@dc010.tj.momo.com init_env]$ date -d "20150416 12:20 10 minute" +"%Y%m%d%H%M"201504161230
The date -d parameter gets more dates we need based on the current date.
This month and next month this_ym=`date +%Y%m`next_ym=`date -d '1month' +%Y%m` yesterday and tomorrow date -d yesterdaydate -d tomorrowdate +%Y % m % d-d "+1 day" date + %Y % m % d --date "+1 day" date + %Y % m % d --date='+1 day' specified month date -d 1May Now: date -d now Other date +%Y%m%d --date="+1 day" //Display date of next day date +%Y%m%d --date="-1 day" //Display date of previous day date +%Y%m%d --date="-1 month" //Display date of previous month date +%Y%m%d --date="+1 month" //Display date of 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. This is the introduction to" How to specify a date minus one day in Shell ". Thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.