My table feeds in mysql has a RSS timestring
column named pubDate
.
I would like to add an additional column pubDate_Date
and insert the RSS timestring
as a real date.
I have created the additional column formatted as DATE
and try to use the following code to update the new column with data, but somehow I cannot get it working. Am a newbie here.
function pubDateToMySql($str){
return date('Y-m-d H:i:s', strtotime($str));
};
$sqlCommand = "SELECT * FROM feeds ORDER BY id ASC";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$id = $row["id"];
$pubDate = $row["pubDate"];
$pubDate_Date = pubDateToMySql($pubDate);
$sql = mysqli_query($myConnection, "UPDATE feeds SET pubDate_Date =
$pubDate_Date WHERE ID = $id");
}
mysqli_free_result($query);
To complete this post, this is how I ended up doing it:
UPDATE feeds SET pubDate_Date = STR_TO_DATE(pubDate, '%a, %d %b %Y %T')