Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set current time field for MySQL

I am trying to set the value of a field via a hidden form field to the current date and time using either PHP or Javascript that would conform to MySQL's datetime field.

like image 708
Rick Avatar asked Nov 27 '25 09:11

Rick


2 Answers

You can use PHP to get and format the current system date/time for use in MySQL like this:

$now = date('Y-m-d H-i-s');
like image 128
Beofett Avatar answered Nov 29 '25 23:11

Beofett


You can directly set current date and time in your SQL insert query using NOW():

INSERT INTO table_name (current_time, column2, column3,...) 
VALUES (NOW(), value2, value3,...)

where current_time is the field where you want to put current date and time.

like image 26
Matteo Alessani Avatar answered Nov 29 '25 22:11

Matteo Alessani