views:

43

answers:

2

Hi,

Description:

I am doing purchasing function, whenever the users make purchases, it will add 1 month privilege to my access special page of my site. I have received some complaints from my users, please read the problem section.

Problem:

Out of 500 users, there are few users, that for example: make purchase today, but the expiration day goes backward, 1 or 2 days, or even months. For example: He purchased on 3 August 2010, the expiration date is 25 May 2010.

My Php code:

The code that I am using to add 1 month before insert into mysql database is:

// I already set the default timezone
$expiryDate = date("Y-m-d H:i:s",strtotime("+1 month"));

I am not sure if its the code is wrong, my server is wrong or the third-party payment gateway is wrong, please advise me how to solve it.

!important question!

What are the possible causes, that can cause the expiration date goes backward?

A: 

If you're storing the expiry time in the database as a date or datetime field, then you should do the update there:

UPDATE table SET expiry=DATE_ADD(expiry, INTERVAL 1 MONTH) WHERE ...;

Full details here.

Marc B
Hi Marc, I have written the updateDB function, that accept arguments, like purchase date, expiry date. because, I may have different kind of purchases (1-day, 2-day etc) in future. Should I modify my function? Or do you have other solution?
web_starter
Read the DATE_ADD docs as linked to in my answer. There's many different interval types you can use, and there's always DATE_SUB if you need to subtract as well. It should be simple enough to set up a mapping function from your PHP date logic to the equivalent MySQL statements. Of course, usually only months are problematic for date calcs. I'd hate to buy a month of access in February only to find out it gives me 28/29 days instead of 30/31 like it would any other time.
Marc B
A: 

There are issues using +1 month with strtotime, there are some solutions on the function document page. However if i were you i would use a tested library like Zend_Date. You could use the sql as suggested but im going to guess thats going to depart from how you organized your DB specific code.

prodigitalson