Reputation: 164
I have table in mysql database which have field with datatype is datetime.
I want to save the datetime in this minute, for this I use " Now() ", but it does not work,
It just save 000000000000 in databaes.
Upvotes: 1
Views: 13449
Reputation: 538
try this: set the 'type' of column named 'date_time' as 'DATETIME' and run the following query:
INSERT INTO my_table (date_time
) VALUES (CURRENT_TIMESTAMP)
Upvotes: 0
Reputation: 1339
If you use php, the correct format is:
date("Y-m-d H:i:s");
UPDATE:
Minutes are expressed as i
not m
Upvotes: 12
Reputation: 4648
An example of a PHP script which sets a date in MySQL manually,
<?php
$query_date = "INSERT INTO tablename (col_name, col_date) VALUES ('DATE: Manual Date', '2008-7-04')”;
mysql_query($query_date) or die(mysql_error());
?>
An example of a PHP script which sets a date in MySQL Automatic,
<?php
$query_date = "INSERT INTO tablename (col_name, col_date) VALUE ('DATE: Auto CURDATE()', CURDATE() )”;
mysql_query($query_date) or die(mysql_error());
?>
Upvotes: 0
Reputation: 12995
I would use function time()
too, then it's easy to output different kind of timestamps with date()
.
$query = "INSERT INTO tbl VALUES (".time().");";
Upvotes: 1
Reputation: 3722
If you've got a timestamp in PHP check out FROM_UNIXTIME() http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_from-unixtime
$tstamp = time();
$query = "INSERT INTO `table` VALUES (FROM_UNIXTIME($tstamp))";
Upvotes: 4
Reputation: 16285
date("g")
this will return 12-hour format of an hour without leading zeros. For more options see http://php.net/manual/en/function.date.php
Upvotes: 0
Reputation: 96159
INSERT ... (Now(), ...)
without additional quotes around the function Now()
Upvotes: 2