Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the following query to update fields in my table if token is matching, but the current date is not getting inserted

$this->wpdb->update(  
            'wp_competitors',  
            array(  
                'results' => $tips,  // json  
                'update_time' => ' CURDATE()' //  
            ),  
            array( 'token' => $token ),  
            array(  
                '%s',   // value1  
                '%d'    // value2  
            ),  
            array( '%d' )  
        );  

than I was trying to use php's date('Y-m-d H:i:s') but no results

share|improve this question

1 Answer 1

From the codex:

<?php $wpdb->update( $table, $data, $where, $format = null, $where_format = null ); ?>

In your exampe ' CURDATE()' is simply a string, not a MySQL function (or something else).

The correct syntax for php's date() is:

date( [format], [timestamp] )

Try this:

$this->wpdb->update(  
            'wp_competitors',  
            array(  
                'results' => $tips,  // json  
                'update_time' => date( 'Y-m-d H:i:s', time() )
            ),  
            array( 'token' => $token ),  
            array(  
                '%s',   // value1  
                '%d'    // value2  
            ),  
            array( '%d' )  
        );

Better than php's date() is WordPress current_time():

current_time( 'mysql' )

This will return something similiar to 2012-12-02 23:00:08

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.