wpdb update add current timestamp not working

You seemed to have solved everything but the issue with the time:

found the issue %d should be %s. but I see that it saves the server
time not the current timezone

WordPress has a number of date/time related functions. In this case, it sounds like what you need is current_time(), which…

Returns the blog’s current local time in one of two formats, either
MySQL’s timestamp data type format (i.e. YYYY-MM-DD HH:MM:SS) or the
Unix timestamp format (i.e. epoch).

So what you should need is:

$wpdb->update(
      'mytable',
      array(
          'value' => 'hello world', 
          'edit'  => current_time( 'mysql' )
      ),
      array(
          'option_name' => 'the row'
      ), 
      array('%s, %s')
);

Leave a Comment