How to get a date from a few days ago or a few days after Linux

Source: Internet
Author: User

In the Linux environment to get a few days before the time just use

date-d "x days Ago" +%y%m%d

X is replaced by a number, if it takes a few days before the direct write positive, if a few days after the date directly write negative numbers can be;

date-d "x weeks Ago" +%y%m%d

X is replaced by a number, if it takes a few weeks before the direct write positive, if a few weeks after the date directly write negative numbers;

date-d "x years ago" +%y%m%d

X is replaced by a number, if it takes a few years before the direct write positive, if a few years after the date directly write negative numbers can be;

Look at the following example:

[Email protected] ~]# date +%y%m%d
20100107

The above is today's date 20100107

[[email protected] ~]# date-d "2 days ago" +%y%m%d
20100105

It's dated two days ago.
[[email protected] ~]# date-d "4 days Ago" +%y%m%d
20100103

above is the date four days ago

[[email protected] ~]# date-d"-1 days Ago "+%y%m%d
20100108
above is a day after the date
[[email protected] ~]# date-d"-2 days Ago "+%y%m%d  
20100109
above is two days after the date

[Email protected] ~]# date-d "1 week Ago" +%y%m%d
20091231
It's a week ago.
[[email protected] ~]# date-d "1 year ago" +%y%m%d
20090107
It was dated a year ago.

How to get a date from a few days ago or a few days after Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.