I am writing a function in WordPress to add data from an XML file to a MySQL database. The problems happened after I got a date value from the XML. It's a string type and I format it to a datetime using this code:
$mysqlDay = date('d/m/Y',strtotime($day));
$day
is a date value retrieved from the XML: "25/01/2013" (d/m/Y). And the value of $mysqlDay
is "01/01/1970" (d/m/Y). Why does the variable $mysqlDay
have value of the beginning day instead the $day
? What should I do if I want to format it from string to date?
In a similar problem to the one above, if I want to convert a string formatted like "18:00" (H:M) to time, what should I do?
I used this code in WordPress to add these values to the database:
$wpdb->insert('wp_lps',
array('date'=>$mysqlDay,
'start'=> $mysqlStartTime,
'end'=> $mysqlEndTime),
array('D/M/Y',
'H:M',
'H:M')
);
Is this right? wp_lps
is the table I created, $mysqlStartTime
and $mysqlEndTime
need to be formatted as H:M.