Adjusting Dates

What is the easiest way to find the date 6 month prior to the current date.

Example:
Today is 2011/01/29
I need to find the 1st day of the month, 6 month ago, which is 2010/08/01. I have to count 1/1/2011 as a previous month, since the current day is past 1/1/2011. Is there any easy function???

Thanks.

with GNU date

date -d '6 months ago' '+%Y/%m/01' 

Doesn't look like I have GNU Date available, is there another option???
Thanks.

Hi,

Test this solution using 'perl'. I had to install the 'DateTime' module using 'cpan'. Here my console session:

$ su -
# cpan
cpan> install DateTime
cpan> exit
# exit
$ cat script.pl
use strict;
use warnings;
use DateTime;

die "Usage: $0 [#months]\n" unless @ARGV && $ARGV[0] =~ /^\d+$/;

my $monthsBefore = $ARGV[0];

my $dt = DateTime->today();
$dt->set_day(1), print($dt->ymd('/'), "\n"), exit if $monthsBefore == 0;

my $cdt = $dt->clone();
$dt->set_day(1);

my $cmp = DateTime->compare($dt, $cdt);
--$monthsBefore if $cmp < 0;
$dt->subtract(months => $monthsBefore);
print $dt->ymd('/'), "\n";
$ perl script.pl 6
2010/08/01

Regards,
Birei

At your shell command prompt typing in

date

does nothing? I have yet to see a distro that didn't come with date. Odd...