Today I am looking for some help with an update I am making to my database. In the previous version of our internal system we used the following styled strings as system logs;
User Admin Logged in from xx.xx.xx.xx - 24/05/2014 - 12:26PM
All times are written to the database in a single string as above, however I am looking to modernize the system and use timestamps so that searches can be done on them. There are several thousand records in the database, all with the time marker as above.
I am looking for assistance in breaking the string, extracting the time and then converting it to a timestamp, saving it to a database thereafter.
So far I have tried to use the following manually just to see what results;
strtotime($string . " UTC+10");
Using terms such as 'now' and 'today' and 'June 31st' seem to work, however the string of '24/05/2014 - 12:26PM' does not.
In addition to that issue, it has come to my attention that the use of / between the date information will then force the script to read it as mm/dd/yyyy instead of dd/mm/yyyy
What is the advised way to proceed, remembering I want to extract these from a database, get the timestamp, save it back to the database all automatically. Server load isnt an issue as it only needs to occur once.
Thank you greatly as always :)
I used the following code based on the answer provided to accomplish this quickly and efficiently. Hope it helps others!
<?php
require_once("config.inc.php");
$ProcessText = '';
$QueryCount = 0;
$sql = mysql_query("SELECT UNIX_TIMESTAMP(STR_TO_DATE(RIGHT(log,20), '%d/%m/%Y - %h:%i%p')),dbid FROM systemlogs WHERE `timestamp` = '';");
while($data = mysql_fetch_array($sql)){
$doupdate = mysql_query("UPDATE `systemlogs` SET `timestamp` = '".$data[0]."' WHERE `dbid` = '".$data[1]."' LIMIT 1");
$ProcessText .= 'Updated: '.$data[1].' | Set Timestamp: '.$data[0];
$QueryCount++;
}
//echo $ProcessText;
echo '<strong>Total Queries Run: '.$QueryCount.'</strong>';
?>