I want to get sysdate -1 and sysdate -2 in variable and echo it. I am using below query which gives todays date as output.
#! /bin/bash
tm=$(date +%Y%d%m)
echo $tm
How to get yesterday and day before yesterdays date?
I want to get sysdate -1 and sysdate -2 in variable and echo it. I am using below query which gives todays date as output.
#! /bin/bash
tm=$(date +%Y%d%m)
echo $tm
How to get yesterday and day before yesterdays date?
Here is another one way,
For yesterday,
For day before yesterday,
Yesterday date
Day before yesterdays date
For any date you can use below one default it take 1 days. If its passing value that day before it take
You can get the yesterday date by this:
and day before yesterday by this:-
For older versions of BSD date (on old versions of macOS for example) which don't provide a
-v
option, you can get yesterdays date by subtracting 86400 seconds (seconds in a day) from the current epoch.Obviously, you can subtract 2 * 86400 away for the day for yesterday etc.
Edit: Add reference to old macOS versions.