Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, OS: RedHad 4 I use below in my .sh script DAY=`(date '+%a')` how can I get DAY_1 to have yesterday's day and DAY_2 to have day for two days ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2008
    Posts
    14

    Yesterday's date on Linux


    Hi,

    OS: RedHad 4

    I use below in my .sh script

    DAY=`(date '+%a')`

    how can I get DAY_1 to have yesterday's day and DAY_2 to have day for two days ago. No luck with the man pages

    Thanks in advance for any help.

  2. #2
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,729
    Hi and Welcome !

    Code:
    DAY_1=`(date --date='1 days ago' '+%a')`
    DAY_2=`(date --date='2 days ago' '+%a')`
    echo $DAY_1 $DAY_2
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  3. #3
    Just Joined!
    Join Date
    Jan 2008
    Posts
    14
    Thank you very much.

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Since my man page doesn't cover that little trick, I went a'googling. I found enough info to help me write this demonstration script:
    Code:
    #!/bin/bash
    
    set -o verbose on
    date
    date --date=now
    date --date=today # same thing
    date --date='3 seconds'
    date --date='3 seconds ago'
    date --date='4 hours'
    date --date='tomorrow'
    date --date='1 day'
    date --date='1 days'
    date --date='yesterday'
    date --date='1 day ago'
    date --date='1 days ago'
    date --date='1 week'
    date --date='1 fortnight'
    date --date='1 month'
    date --date='1 year'
    Running it gave this output:
    Code:
    date
    Thu Jan  3 07:42:47 PST 2008
    date --date=now
    Thu Jan  3 07:42:47 PST 2008
    date --date=today # same thing
    Thu Jan  3 07:42:47 PST 2008
    date --date='3 seconds'
    Thu Jan  3 07:42:50 PST 2008
    date --date='3 seconds ago'
    Thu Jan  3 07:42:44 PST 2008
    date --date='4 hours'
    Thu Jan  3 11:42:47 PST 2008
    date --date='tomorrow'
    Fri Jan  4 07:42:47 PST 2008
    date --date='1 day'
    Fri Jan  4 07:42:47 PST 2008
    date --date='1 days'
    Fri Jan  4 07:42:47 PST 2008
    date --date='yesterday'
    Wed Jan  2 07:42:47 PST 2008
    date --date='1 day ago'
    Wed Jan  2 07:42:47 PST 2008
    date --date='1 days ago'
    Wed Jan  2 07:42:47 PST 2008
    date --date='1 week'
    Thu Jan 10 07:42:47 PST 2008
    date --date='1 fortnight'
    Thu Jan 17 07:42:47 PST 2008
    date --date='1 month'
    Sun Feb  3 07:42:47 PST 2008
    date --date='1 year'
    Sat Jan  3 07:42:47 PST 2009
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •