myqsl - inserting time into database
Moderator: General Moderators
-
alexislalas
- Forum Commoner
- Posts: 44
- Joined: Sun Feb 19, 2006 10:09 pm
myqsl - inserting time into database
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.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
-
alexislalas
- Forum Commoner
- Posts: 44
- Joined: Sun Feb 19, 2006 10:09 pm
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
You construct the time string before inserting it, or you can do it during insert.
For MySQL I would use backticks around the fieldnames, especially if there is a chance of a reserved name conflict...
If your time stamp is comprised of variables, you can assign those values at insert time...
(using PHP)
Code: Select all
INSERT INTO table (timefield) VALUES ('23:23:00');Code: Select all
INSERT INTO `table` (`timefield`) VALUES ('23:23:00');(using PHP)
Code: Select all
<?php
$sql = "INSERT INTO `table` (`timefield`) VALUES ('$hour:$minute:$second')";
?>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA