faqts : Computers : Programming : Languages : PHP : Common Problems : Forms and User Input

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 20 people (35%) answered Yes
Recently 2 of 10 people (20%) answered Yes

Entry

How do I convert form values into MySQL datetime format using php?

Aug 6th, 2003 19:48
Justin Dalrymple, Joe Calino,


You'll want to string your variables together into the proper format.
PHP does this by putting a "." between fields that need to be concatenated.
Example:
<?php
// You'll want to remove these since you are using data from your form
$year = "2003";
$month = "08";
$day = "06";
$hours = "22";
$minutes = "01";
$seconds = "35";
$date = $year . "-" . $month . "-" . $day;
$time = $hours . ":" . $minutes . ":" . $seconds;
$datetime = $date . " " . $time;
// Print it out
echo ($datetime);
?>