Difference between two dates greater than 3 months [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

Difference between two dates greater than 3 months [SOLVED]

Post 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
Last edited by hairyjim on Fri Dec 01, 2006 10:01 am, edited 1 time in total.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

The following may be a little more readable

Code: Select all

if(strtotime("+3 months", $timestamp1) < $timestamp2) {
   // three months has past
}
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

Post 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
Post Reply