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

    Join Date
    Sep 2000
    Rep Power
    I have a form that posts toa mysql database but I cheated on the date. Iused a Varchar insted of the date. I need to figure out how to make the form using drop down boxes for month and day that will send the info toa date feild in the table. Then when my other page gets the infofrom the table I dont want it to read 2000-10-2. Can anyone help?
    Thank You Soooo Much!
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Caro, Michigan
    Rep Power
    This is a very common question. People think that since MySQL stores the date/time info as yyyymmddhhmmss, that's the only way you can pull it out of the database and you have to use regular expressions to get it into a human readable format. No so.

    MySQL has a date_format() function where you can pull it out in any format you want, please look at the manual at:

    Also, for your question, make your dropdown boxes, Jan-Dec, 1-31, 2000-2010 or whatever years you want. Then look at the mktime() function in PHP.

    $unix_time = mktime(0,0,0,$month,$day,$year)

    mktime returns a unix timestamp. Now, you're asking yourself how to I get a unix timestamp into a mysql date format??

    Using PHP, you can do:

    $mysql_date = date("Ymd",$unix_time);
    //format will be yyyymmdd

    Or, using MySQL, you can do the following:

    INSERT INTO your_table (date_column) values (from_unixtime($unix_time))

    Hopefully this gets you going. Take a look at all of the date and time functions in the PHP and MySQL manuals, and they should answer any further questions you have.

    ---John Holmes...

Similar Threads

  1. Creating HTML forms _easily_
    By ezuk in forum HTML Programming
    Replies: 0
    Last Post: October 21st, 2003, 03:24 AM
  2. random forms problem in php/mysql
    By Treetaliano in forum MySQL Help
    Replies: 2
    Last Post: September 12th, 2003, 04:39 AM
  3. PHP/mySQL books
    By bradbrevet in forum PHP Development
    Replies: 4
    Last Post: August 8th, 2003, 10:11 AM
  4. random forms problem with php/mysql
    By Treetaliano in forum PHP Development
    Replies: 1
    Last Post: July 29th, 2003, 11:58 AM
  5. PHP/MySQL Issues... Please help.
    By misteraven in forum PHP Development
    Replies: 14
    Last Post: August 7th, 2002, 08:03 PM

IMN logo majestic logo threadwatch logo seochat tools logo