#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    15
    Rep Power
    0
    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?
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    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));
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    15
    Rep Power
    0
    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?
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    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.

Similar Threads

  1. DATE_ADD question where date YYYYMMDD
    By lottos in forum PHP Development
    Replies: 5
    Last Post: February 22nd, 2004, 07:53 PM
  2. database date selection problem
    By kidsleep in forum MySQL Help
    Replies: 0
    Last Post: January 31st, 2004, 10:50 AM
  3. Question regarging date
    By Verted in forum PHP Development
    Replies: 1
    Last Post: December 23rd, 2003, 04:58 PM
  4. SYBASE Question with last month end date
    By llccoo in forum Database Management
    Replies: 0
    Last Post: December 21st, 2003, 03:00 PM
  5. Unusual date question
    By cadster in forum PHP Development
    Replies: 5
    Last Post: December 16th, 2003, 08:53 AM

IMN logo majestic logo threadwatch logo seochat tools logo