Page 1 of 1

Difference between two dates greater than 3 months [SOLVED]

Posted: Fri Dec 01, 2006 5:47 am
by hairyjim
Hi All,

I was just wondering what the best way was to compare two dates and to check if the difference was greater than 3 months. Id like it to be pretty accurate not to the second but to the day would suffice.

I was thinking of just doing the following but it is a bit inaccurate, assuming there are 30 days each month that is.

(60 * 60 *24 *30 *3 = sec's in a 3 month period)

Code: Select all

If ($timestamp2- $timestamp1 > 7776000  ) {

// send new questionnaire

}
Im happy to run with this but the point of doing this is to send a new questionnaire out to people that have had a support incident but have NOT had the questionnaire sent out in the last 3 months.

Thanks.

James

Posted: Fri Dec 01, 2006 9:29 am
by aaronhall
The following may be a little more readable

Code: Select all

if(strtotime("+3 months", $timestamp1) < $timestamp2) {
   // three months has past
}

Posted: Fri Dec 01, 2006 10:01 am
by hairyjim
Oh great.

I will have to read what exactly is happening there with the +3 months thingy just so I understand it.

Ta muchly.

Jim