wpdb update add current timestamp not working

So using the $wpdb->update to add some data to a custom table, trying to add the current timestamp but it’s not saving the right stuff(0000-00-00 00:00:00 this is saved).

overview code

  $wpdb->update('mytable',
      array(
          'value' => 'hello world', 
          'edit'  => date("Y-m-d h:i:s") //saves 0000-00-00 00:00:00
      ),
      array(
          'option_name' => 'the row'
      ), 
      array('%s, %s')
  );

Related posts

1 comment

  1. 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')
    );
    

Comments are closed.