I am creating an insert query following the insert example on the wpdb class reference. What sprintf like placeholder should be used for a DateTime column on a custom table? Allowed placeholders seem to be %s (string), %d (integer) and %f (float). In my example below I have set the DateTime column to use a %s string value, is this correct?

The example below simplifies my situation.

Table creation

global $wpdb;
$sql = "CREATE TABLE $wpdb->prefix. 'time' (
       id bigint(20) NOT NULL AUTO_INCREMENT,
       time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
       UNIQUE KEY id (id)
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );


    $wpdb->prefix. 'time',
        'time' => current_time( 'mysql' )

The wpdb class reference I have been using is linked below. http://codex.wordpress.org/Class_Reference/wpdb#Placeholders

1 Answer 1


Upon testing this on my demo site it seems to work perfectly well simply storing DateTime columns as a %s (String). After inserting like this the database reports the DateTime column exactly as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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