-3

I have a database that you converted to WordPress History in the old database (1472877023) And the new (2014-05-16 18:49:52) I did this code but it does not work

$Sql = mysql_query("SELECT * FROM no620_content3 ");
while ($row= mysql_fetch_array($Sql)) {
    $dates = date("m-d-Y h:g:i ",$row['date_time']);
    $arid=$row['id'];
    $query = "UPDATE wp_posts SET ' post_date' = '$dates' WHERE ID = '$arid' ";
    mysql_query($query);
}
Don't Panic
  • 41,125
  • 10
  • 61
  • 80
  • is your field type set correctly in db? if u are passing a date time and your field is set as int type, it wont be updated. – Kimberlee Ho Apr 27 '17 at 15:48
  • The **[edit]** button is on the bottom left of your question, under the tags. Code in comments is very difficult to read. – Don't Panic Apr 27 '17 at 15:51
  • 1
    mysql stores datetime as YYYY-mm-dd 00:00:00 and not what you have there. – Funk Forty Niner Apr 27 '17 at 15:51
  • 1
    then `SET ' post_date'` that alone is failing; invalid identifier qualifiers (and a space). `mysql_error()` would have told you about that. – Funk Forty Niner Apr 27 '17 at 15:52
  • ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Apr 27 '17 at 15:54
  • have the answerers below seen my comments? they need explanations given and should not rely solely on my comments. – Funk Forty Niner Apr 27 '17 at 16:00
  • I have, @Fred-ii- , why do you ask? – Don't Panic Apr 27 '17 at 16:03
  • @Don'tPanic to a certain extent; yes you have. Not about the quotes/space for the column ;-) – Funk Forty Niner Apr 27 '17 at 16:05

2 Answers2

0

Your DateTime format is wrong:

$dates = date("m-d-Y h:g:i ",$row['date_time']);

To get this 2014-05-16 18:49:52, you need to change that to:

$dates = date("Y-m-d H:i:s ",$row['date_time']);

Consider using the DateTime class too. And start using PDO, as the mysql_ commands are all deprecated and removed in all supported versions of PHP.

http://php.net/manual/en/class.pdo.php

http://php.net/manual/en/class.datetime.php

delboy1978uk
  • 12,118
  • 2
  • 21
  • 39
0

There's no need to execute a bunch of queries in a loop for this. You can do it with one query.

UPDATE no620_content3 SET post_date = FROM_UNIXTIME(date_time)
Don't Panic
  • 41,125
  • 10
  • 61
  • 80