Subject: Date and month ago

From: Tuc at T-B-O-H <[email-masked]>
Date: Mon, 3 Dec 2012 14:53:05 -0500 (EST)

Hi,

Running into a problem with date and month...

-------------------------------------------------------------------
#!/bin/bash

function example {
  rptdate=$(date +%Y-%m-%d -d "$1 -6 months")
  echo "6 months ago from $1 is ${rptdate}"
}

example 2012-09-30
example 2012-10-31
example 2012-10-30
example 2012-11-30
example 2012-12-01
example 2012-03-31
-------------------------------------------------------------------

6 months ago from 2012-09-30 is 2012-03-30
****6 months ago from 2012-10-31 is 2012-05-01***
6 months ago from 2012-10-30 is 2012-04-30
6 months ago from 2012-11-30 is 2012-05-30
6 months ago from 2012-12-01 is 2012-06-01
*****6 months ago from 2012-03-31 is 2011-10-01*

It seems that its running into the issue that if the 6 months ago doesn't
have the same amount of days, its falling into the next month. Is there a
way to tell it to instead just use the last day of the month?

Thanks, Tuc