MySQL Forums
Forum List  »  PHP

Datetime conversion fails
Posted by: ed ziffel
Date: August 19, 2011 03:26PM

Trying to convert 8/29/2008 01:10 varchar data to datetime.

have test database setup: buthead
test tables:
asdf, with one field: date1_original VARCHAR(55)

where 12 records with the above format are
8/29/2008 01:10
8/01/2008 02:20
8/08/2008 03:30
8/01/2008 04:40
8/13/2008 07:07
8/14/2008 08:08
8/14/2008 09:09
8/15/2008 10:11
8/16/2008 11:11
8/17/2008 12:31
8/22/2008 22:22
8/30/2008 23:33.

And table datesort, with with one field: daties TIMEDATE

that is empty, unless just after I run my query then it has all zeros 0000-00-00 00:00:00 until I empty it.

Code is in place to connect to the server and select a database that is working as it should.

My query to convert the string to timedates is:

$sql1="INSERT INTO date_sort (daties) SELECT STR_TO_DATE(Date1_original,'%c%e%Y%H:%i') FROM asdf;";
$result = mysql_query($sql1);
if(!$result) {
echo "Date conversion did not work ".mysql_error();
else {
echo "Date conversion worked."."<br/>";

echo "<br/>";

get the Date Conversion worked. message when running the query.

Still get just zeros. Have tried a bunch of different conversion strings. Still zeros. Got to be something wrong that I'm just not figuring out.

Options: ReplyQuote

Written By
Datetime conversion fails
August 19, 2011 03:26PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.