October 2nd, 2000, 04:38 PM
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!
October 2nd, 2000, 05:46 PM
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.