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
Insert into MySQL from PHP form text field
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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
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
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
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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';
}