Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Problem

Status
Not open for further replies.

mcmon999

IS-IT--Management
Mar 3, 2005
21
GB
Hi,

i have some code that allows the using to input the date.

how do i join the day, month and year so it can be reversed into MySQL date format?

is this the easiest way to create a date drop down?

Code:

<tr>
<td>Shift Date</td>
<td><div align="left">
<?php

$months = range(1,12);
$days = range (1, 31);
$years = range (2005, 2006);

echo '<select name="day">';
foreach ($days as $value) {
echo "<option value=\"$value\"> $value</option>\n";
}
echo '</select>';

echo '<select name="month">';
foreach ($months as $key => $value1) {
echo "<option value=\"$key\"> $value1</option>\n";
}
echo '</select>';

echo '<select name="year">';
foreach ($years as $value2) {
echo "<option value=\"$value2\"> $value2</option>\n";
}
echo '</select>'

?>
</div></td>
</tr>

Thanks in Advance!!
 
You have several options:
1. Concatenate the parts into a string to the desired date format.
2. Make an actual date out of it with strtotime() and use a formatting function to reformat. (Kind of overkill).

Your dropdown is good. It eliminates the confusion how the date is formatted.
Code:
$date_str = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
 
thanks for responding,

i've now got the problem where if 1 is selected for the month it will insert 00 and 2 will insert 01.

the range for month is 1, 12

any ideas why this is occuring??

for code see first post.

 
change the sequence:

foreach ($months as $key => $value1) {
echo "<option value=\"$key\"> $value1</option>\n";
}

in

foreach ($months as $key => $value1) {
echo "<option value=\"$value\"> $value1</option>\n";
}


you know: the keys of array are starting from 0 .



___
____
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top