45

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

Can you please tell me how to do that?

ivanleoncz
  • 9,070
  • 7
  • 57
  • 49
Abhi
  • 5,501
  • 17
  • 78
  • 133

2 Answers2

89

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);
?>
xeruf
  • 2,602
  • 1
  • 25
  • 48
Harry Joy
  • 58,650
  • 30
  • 162
  • 207
20

Another option:

UPDATE `table` SET the_col = current_timestamp

Looks odd, but works as expected. If I had to guess, I'd wager this is slightly faster than calling now().

Madbreaks
  • 19,094
  • 7
  • 58
  • 72
  • 7
    Should not be fast, as according this (https://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html) it's just a synonym for now() – Jimmy Koerting Jun 21 '15 at 12:34