Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Shell specify a date minus one day

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report