Inserting a DATE into a MySQL DATE field

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Moonspell
Forum Newbie
Posts: 21
Joined: Tue May 13, 2003 4:54 pm

Inserting a DATE into a MySQL DATE field

Post 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?
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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.
Moonspell
Forum Newbie
Posts: 21
Joined: Tue May 13, 2003 4:54 pm

Post by Moonspell »

So then I can just insert $date into the date field, correct? It can just be a variable? Thanks a lot!
Post Reply