Getting sysdate - 2 by an unix command

How can I get an equivalent in unix for the following Oracle SQL command:

select sysdate - 2 from dual;

Thanks

Jos�

Here is one way:

#!/usr/bin/sh
_day=`date +%d`
_month=`date +%m`
_year=`date +%y`
newday=`expr $_day - 2`
echo "Two days ago was $_month/$newday/$_year "

I know the GNU date provides an easier way, but this is more portable...

your to_char function is up to you :stuck_out_tongue:

Except if you run it on the 1st, then 1-2 = -1. Oops.

A portable solution is to convert the current date to a julian value, subtract 2 and then convert back to a gregorian value. A script to convert to/from julian date is here: http://droflet.net/julian.txt

this login does not work with number greater than the days passed in the going month.
plz try this script it will fail .

#!/usr/bin/sh
echo "Plz enter the number of diff required"
read _diff
_day=`date +%d`
_month=`date +%m`
_year=`date +%y`
newday=`expr $_day - $_diff`
echo "Two days ago was $_month/$newday/$_year "

Yeah, that is the shortcoming that PxT pointed out in my script also. I like his idea better of converting to julian date, subtracting the number you need, then converting back to regular date. Please check out his script - it's much better, and is less likely to contain the simple errors I have included (as features, of course) in mine. :stuck_out_tongue: