September 4th, 2000, 02:57 PM
I am using the following to produce a registration and expiry date and then save this to a MySQL db
$regdate = gmdate("Y-m-d H:i:s");
$expdate = "0000-00-00 00:00:00";
At the moment I am changing the expiry date manually, but what I would like to do is take the registration date and add 1 month to this and then save it to the db. I have scoured the manual but my head is now in a spin...please could somebody show me a simple way of acieving this?
September 4th, 2000, 04:50 PM
You should be using MySQLs built in date/time types and functions rather than trying to manipulate PHP types and functions.
insert into table (regdate,expdate) values (now(),adddate(now(), interval 1 month));
September 4th, 2000, 05:35 PM
Cheers Rod. Thats useful. Except there is a problem for me doing it that way. Having read the MySQL manual I see that the format of the date field must be YYYY-MM-DD. Now I live in the UK and require this date to be displayed in the British form of DD-MM-YYYY. Also, would'nt now() give me the server time which is PST whereas I need GMT. Surely this means I will still have to manipulate these values in PHP to display them as needed?
September 5th, 2000, 12:50 AM
As far as formatting, check out the date_format function of mysql in the manual.
Didn't register that you were using gmdate. Hmm, you could generate the gm unixtimestamp and do this:
insert into table (regdate,expdate) values (from_unixtimestamp($gmtstamp),adddate(from_unixtimestamp($gmtstamp), interval 1 month));
Check the from_unixtimestamp() I may be wrong on the name but it's there. Also, I didn't mention that you would need to use a DATETIME datatype for the fields.