Add X days to a particular date in BASH

后端 未结 2 1823
栀梦
栀梦 2020-12-04 04:09

Totally new to BASH. Apologies in advance.


Problem

I\'d like to add X days to a specific date.


Code

相关标签:
2条回答
  • 2020-12-04 04:38

    You can do this way:

    dt='2017-09-20'
    
    date -d "$dt +1 day"
    Thu Sep 21 00:00:00 EDT 2017
    
    date -d "$dt +2 day"
    Fri Sep 22 00:00:00 EDT 2017
    

    It seems OP is using OSX. You can use date addition this way:

    s='20/09/2017'
    date -j -v +1d -f "%d/%m/%Y" "$s"
    
    Thu Sep 21 14:49:51 EDT 2017
    
    0 讨论(0)
  • 2020-12-04 04:38

    You can do something like this:

    date -d "Sun Sep 6 02:00:00 IST 2012+10 days"
    
    0 讨论(0)
提交回复
热议问题