Page 1 of 1
myqsl - inserting time into database
Posted: Mon Jun 12, 2006 4:57 pm
by alexislalas
i have a menu/list for the hours and for the minutes. whats the syntax to insert them into the database. i asigned that field the time datatype.
Posted: Mon Jun 12, 2006 5:04 pm
by RobertGonzalez
HH:MM:SS on a 24 hour time cycle... 11:23 PM would be 23:23:00.
Posted: Mon Jun 12, 2006 5:19 pm
by alexislalas
yeah, but how would the sql syntax look like:
INSERT INTO table (variable) values (????)
if my variables have names like: hr, min, sec should it look something like INSERT INTO table (variable) values (hr:min:sec) or is that not capable?
Posted: Mon Jun 12, 2006 6:11 pm
by RobertGonzalez
You construct the time string before inserting it, or you can do it during insert.
Code: Select all
INSERT INTO table (timefield) VALUES ('23:23:00');
For MySQL I would use backticks around the fieldnames, especially if there is a chance of a reserved name conflict...
Code: Select all
INSERT INTO `table` (`timefield`) VALUES ('23:23:00');
If your time stamp is comprised of variables, you can assign those values at insert time...
(using PHP)
Code: Select all
<?php
$sql = "INSERT INTO `table` (`timefield`) VALUES ('$hour:$minute:$second')";
?>
Posted: Mon Jun 12, 2006 6:28 pm
by alexislalas
thanks everah!!!
Posted: Tue Jun 13, 2006 8:39 am
by RobertGonzalez
No problem. Glad it helped.