Question:
please any one help me i need a coding for inserting current datetime in mysql using php.?
Edwin
2010-10-28 22:46:56 UTC
am creating a login form using php code.i have a column name of created_date in my database, in that i want to insert created datetime of user account, type=datetime.
Five answers:
vasu
2010-10-29 00:38:01 UTC
To get the current time, use MySQL's built in function NOW(). NOW() contains both the date and time information.



PHP & MySQL Code:




$query_auto = "INSERT INTO timeplayground (dp_time)

VALUE ( NOW() )";



mysql_query($query_auto) or die(mysql_error());

?>

--------------------------------------------------------------------------------------------
Vivi
2010-10-28 23:11:17 UTC
Set your field of time in mysql with DATETIME. When you insert some fields using PHP, you can make the time field blank while others the actual value. The time field in mysql will automatically be the current time;
Vinay
2010-10-29 06:20:12 UTC
I think you don't have need to write special php code for that if you have taken data type as DATE or TIMESTAMP,



use CURTIME() or CURDATE() and for both CURRENT_TIMESTAMP() these are some mysql functions which is use to insert date, time in database



Here is some additional functions of MySQL for inserting the date and time in database

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
?
2016-12-03 07:31:54 UTC
a million. avert using variables that have the sme call as key words or purposes! (which comprise "date": that's a function => date("Y-m-d"), and that's a key-word in mysql ("date"). Use a variation of it, which comprise "datum". 2. For the date format you're using, your container "date_reserved" ought to have a default fee of "00-00-00 00:00:00" in mysql. 3. Then: $datum = date('Y-m-d H:i:s'); $sq. = mysql_query ("INSERT INTO `reservation` (`date_reserved`) VALUES ('" . $datum . '") or die (mysql_error()); (be conscious correction of syntax besides...)
devanathan Thiru
2010-10-28 22:53:16 UTC
use this query,



select getdate();



getdate() funtion will give you the current date in server.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...