Date Validation in unix

I have a script which is take date as parameter

sh abc.sh <2010-02-01>

#!/sh/bin

my_date=$1
#Here i want to two diffrent dates
## 3 Days before
##date14query=$mydate - 4 (it will be 2010-01-28)
##date24query=$mydate +4 (it will be 2010-01-05)

#Please Help

$ 
$ ##
$ echo "2010-02-01" | perl -M"Date::Calc qw(:all)" -ne '@x=split/-/;
>   printf("%04d-%02d-%02d\n%04d-%02d-%02d\n",Add_Delta_Days(@x,-4),Add_Delta_Days(@x,4))'
2010-01-28
2010-02-05
$ 
$ 

I think $mydate + 4 should be 2010-02-05 and not 2010-01-05.

tyler_durden

And some more golf... :wink:

$ 
$ echo "2010-02-01" | perl -M"Date::Calc qw(:all)" -ne '@x=split/-/; $fmt="%04d-%02d-%02d\n";
>   printf("$fmt$fmt",Add_Delta_Days(@x,-4),Add_Delta_Days(@x,4))'
2010-01-28
2010-02-05
$

I've done this a bunch, but don't have anything handy. Usually I'd recommend you create a hash with the months and how many days they have (don't forget a special exception for leap years). Then just subtract the number you want from the current day, if that number is less than 1, add the negative number to the previously created hash with the number of the days in it and this will give you the difference.

Thank u very much durden_tyler..

Perl one liner is very powerful na. If you have any stuff on perl one liner then pls, give me