Deepak
Deepak

Reputation: 414

Unable to INSERT time in data base using MYSQL query

I am trying to INSERT time which is in format "Tue, 14 Jan 2014 19:56:09 +0530" using query

   INSERT INTO monitor (Date, Name ) VALUES ('$Date','$Name') ";
   mysql_query($query) or die ("query failed");

This query execute without any error but when I look into values inserted it was found that value of time in different other than what is in $Date , value inserted is "0000-00-00 00:00:00" other than "Tue, 14 Jan 2014 19:56:09 +0530". Is any their anything I am doing wrong.

Upvotes: 0

Views: 63

Answers (1)

Kermit
Kermit

Reputation: 34055

  1. You need to format it using STR_TO_DATE() inline with your INSERT. For example, SELECT STR_TO_DATE('01,5,2013','%d,%m,%Y'); ... Use the specifiers in this table
  2. Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which.
  3. You have no error handlers

Upvotes: 5

Related Questions