1

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.

4
  • 2
    Can you please provide the code? Commented Dec 7, 2009 at 20:52
  • 2
    Please take the time to use correct spelling and grammar if you want people to help you. Then, post your code snippet of SQL or PHP. Commented Dec 7, 2009 at 20:53
  • 2
    And accept your answer if you wish that we will help you! Commented Dec 7, 2009 at 20:54
  • Table structure can also help Commented Dec 7, 2009 at 21:43

7 Answers 7

12

If you use php, the correct format is:

date("Y-m-d H:i:s");

UPDATE: Minutes are expressed as i not m

Sign up to request clarification or add additional context in comments.

1 Comment

I always use this too... nice to see that other people use this way too.
4

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))";

Comments

2
INSERT ... (Now(), ...)

without additional quotes around the function Now()

Comments

1

I would use function time() too, then it's easy to output different kind of timestamps with date().

$query = "INSERT INTO tbl VALUES (".time().");";

Comments

0

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

Comments

0

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());
?>

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.