[wp-hackers] error in using wp_insert_comment. date puzzle.

Haluk Karamete halukkaramete at gmail.com
Fri Aug 3 01:23:13 UTC 2012

I am trying to programmatically insert comments in  a bulk operation as
part of migration routine.
Comments are in a SQL server table.

I receive the date info from the SQL server table field and store it in a
PHP variable like the following way;

while( $row = sqlsrv_fetch_array( $RS, SQLSRV_FETCH_ASSOC))
$the_date = $row['the_date'];

var_dump view of the $the_date is as follows;

object(DateTime)#97 (3) {
  string(19) "2012-07-30 00:00:00"
  string(3) "UTC"
then I prep my wp_insert_comment's data array.
var_dump view of that data array  as follows;

array(7) {
  string(5) "73615"
  string(14) "Joe  (USA)"
  string(20) "user at domain.com"
  string(2001) "commment text here"
  object(DateTime)#97 (3) {
    string(19) "2012-07-30 00:00:00"
    string(3) "UTC"

After the wp_insert_comment operation, I get a 0 in return - indicating an

And the following message stops the whole process.

Warning: preg_match() expects parameter 2 to be string, object given in
F:\inetpub\....\wp-includes\formatting.php on line 1868

Fatal error: Uncaught exception 'Exception' with message
'DateTime::__construct() expects parameter 1 to be string, object given' in
F:\inetpub\....\wp-includes\formatting.php:1872 Stack trace: #0
DateTime->__construct(Object(DateTime)) #1
get_gmt_from_date(Object(DateTime)) #2 F:\inetpub\...\comments.php(259):
wp_insert_comment(Array) #3 F:\inetpub\...\comments.php(100):
HandleComments(Resource id #25, '73615', 'services.articl...',
'XYZ1207-5206') #4 {main} thrown in
F:\inetpub\....\wp-includes\formatting.php on line 1872

How can I go around this problem and store the date properly?  2012-07-30

More information about the wp-hackers mailing list