Get the date (a day before current time) in Bash

Get the date (a day before current time) in Bash

Asked on December 17, 2018 in Bash.
Add Comment


  • 3 Answer(s)

    The simple way to get the date in bash is here,

    In case that you have GNU date ,

    $ date +%Y:%m:%d -d "yesterday"
    2009:11:09
    

    or try this one,

    $ date +%Y:%m:%d -d "1 day ago"
    2009:11:09
    
    Answered on December 17, 2018.
    Add Comment

    The this solution,

    We can do this code simply, if you just have BSD date,

    date -j -v-1d
    Wed Dec 14 15:34:14 CET 2011
    

    Do this for date calculations on an date of arbitary :

    date -j -v-1d -f "%Y-%m-%d" "2011-09-01" "+%Y-%m-%d"
    2011-08-31
    
    Answered on December 17, 2018.
    Add Comment

    Try this one line code,

    date --date='-1 day'
    
    Answered on December 17, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.