Page 1 of 1
Insert into MySQL from PHP form text field
Posted: Tue Oct 04, 2005 2:43 pm
by murph2481
So if i have a text box and then I want to capture that text box value as a date value and insert it into a MySQL database to a datetime type field how can i do that? Right now no value is captured i just get 0000/00/00.
Ideally if someone has a function that i can call that would format the $_POST['date'] value to what MySQL needs for the SQL statement that would be awesome.
Thanks in advance,
Dan
Posted: Tue Oct 04, 2005 2:47 pm
by feyd
depending on the formats you wish to support (there are so so many) you may simply want to use
strtotime() to get a unix timestamp, which you can give to MySQL's
FROM_UNIXTIME()
Date
Posted: Tue Oct 04, 2005 3:03 pm
by murph2481
Actually even easier just change the format from 10/4/2005 to 2005-4-10 and it will work.
Anyone have a good parser to pull out each value (10,4,2005) and then change the order and the delimeter? Basically i want to change 10/4/2005 to 2005-10-4?
Thanks,
Dan
Posted: Tue Oct 04, 2005 3:29 pm
by John Cartwright
Code: Select all
#Convert 10/4/2005 to 2005-4-10
function dateConverter($date) {
$array = explode('/',$date);
$array = array_reverse($array);
$array = implode('-',$array);
return $array;
}
echo dateConverter('10/4/2005');
echo 'Correct Value: 2005-4-10';
}
Perfect
Posted: Tue Oct 04, 2005 4:13 pm
by murph2481
Perfect thank you
Dan
