Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update MySql timestamp column to current timestamp on PHP?

I want to update the columns of data type timestamp manually through my PHP code.

Can you please tell me how to do that?

like image 429
Abhi Avatar asked May 03 '11 12:05

Abhi


People also ask

How do you change the timestamp?

Syntax – Update value to Current TimestampALTER TABLE table_name updates table schema. CHANGE column_name updates the column to. column_name TIMESTAMP NOT NULL defines the column as of datatype TIMESTAMP. DEFAULT CURRENT_TIMESTAMP sets the default value of the column to CURRENT_TIMESTAMP.

How can I insert current date in MySQL using PHP?

The simplest method to insert the current date and time in MySQL is to use the now() function. Once you call the function, it returns the current date and time in the system's configured time zone as a string. The value returned from the now() function is YYYY-MM-DD for the date and HH-MM-SS-UU for the time record.


1 Answers

Use this query:

UPDATE `table` SET date_date=now(); 

Sample code can be:

<?php $con = mysql_connect("localhost","peter","abc123"); if (!$con)   {   die('Could not connect: ' . mysql_error());   }  mysql_select_db("my_db", $con);  mysql_query("UPDATE `table` SET date_date=now()");  mysql_close($con); ?> 
like image 121
Harry Joy Avatar answered Sep 28 '22 23:09

Harry Joy