Database: Custom table: sprintf value for DateTime column

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 );

Insert

$wpdb->insert(
    $wpdb->prefix. 'time',
    array(
        'time' => current_time( 'mysql' )
    ),
    array(
        '%s'
    )
);

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.

Leave a Comment