MySQL Forums
Forum List  »  PHP

Warning: date_format() expects parameter 1 to be DateTime WHAT?!?!
Posted by: David Shea
Date: March 31, 2010 12:27PM

Here is the test code I created because this will not work in context, so I thought I'd try to isolate as many variables as possible...

<?php
$user="username";
$password="password";
$database="dickandballs";

mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO test VALUES ('', NOW(),'balls')";
mysql_query($query) or die("wtf");

@mysql_select_db($database) or die("Unable to load comments.");
$query2 = "SELECT * FROM test WHERE name='balls'";

$result = mysql_query($query2);
$output = mysql_result($result, '0', 'time');
$date = DATE_FORMAT($output,'%W, %M');
mysql_close();

print("OUTPUT: " . $output . "<br>");
print("FORMATTED DATE: " . $date);

//WTF?! why won't THIS even work????
$toprint = DATE_FORMAT('2010-03-31 13:01:19','%W, %M');
print("DATE: " . $toprint);
?>



If you look at the bottom, even that doesn't work... I don't understand. I am new to mySQL and I've got a pretty good understanding of PHP. BUT, I don't get it.

Is the value in my table not right or something? The last test should work...


All I want to do is format my date and time... *sob*

Options: ReplyQuote


Subject
Written By
Posted
Warning: date_format() expects parameter 1 to be DateTime WHAT?!?!
March 31, 2010 12:27PM


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.