Page 1 of 1

Inserting a DATE into a MySQL DATE field

Posted: Mon Jun 30, 2003 5:33 pm
by Moonspell
Hello! I have 3 HTML drop down menus which have different choices depending on the date. For example, they can choose January - December, 0-12 for the month, and 0-31 for the day. I want to take their info, convert it in date format (is this such a thing?) and insert it into a DATE field in MySQL.

In MySQL-Front the column is represented as 00-00-0000. How do I insert the date that they selected?

Finally, I need to run some for of query like this:

SELECT * FROM table (where the date is between this and this)

How would I run that?

Posted: Mon Jun 30, 2003 6:36 pm
by DuFF
For inserting the date(which is represented by 0000-00-00) I would look at implode(). You can implode the 3 values that each of the drop-down menus. Heres an example:

Code: Select all

<?php
$year=2003;
$month=06;
$day=30;
$datearray = array('$year', '$month', '$day');
$date = implode("-", $datearray);
echo $date; // 2003-06-30
?>
For your second question, I have seen examples like that at MySQL.com. Try looking around here.

Posted: Mon Jun 30, 2003 7:40 pm
by Moonspell
So then I can just insert $date into the date field, correct? It can just be a variable? Thanks a lot!