Jump to content

display datetime from an array variable


dubesinhower

Recommended Posts

i'm using an array to display different variables from mysql entries. i'm trying to display the date, but it keeps giving me an error:Warning: date_format() expects parameter 1 to be DateTime, string given in (blah) on line (blah)what's the best way for me to display the time using arrays? my relevant code is below.

<?php	require("scripts/config.php");	mysql_connect($db_host, $db_user, $db_password) or die(mysql_error());	mysql_select_db($db_database) or die(mysql_error());			if(isset($_GET['pagenum']))	{	$pagenum = $_GET['pagenum'];	}	else	{	$pagenum = 1;	}		$result = mysql_query('SELECT ID FROM linkstab') or die(mysql_error());	$num_rows = mysql_num_rows($result);	$page_rows = 4;	$last = ceil($num_rows/$page_rows);		if ($pagenum < 1) { 		$pagenum = 1;	}	elseif ($pagenum > $last) { 		$pagenum = $last; 	}		$max = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;	$result_p = mysql_query("SELECT * FROM linkstab ORDER BY ID DESC " . $max) or die(mysql_error());?><?php	while ($row = mysql_fetch_array($result_p)) {		echo '<div class="contentBlock bar">';			echo '<div class="contentDesc">';				echo '<dl>';					$linkdate = $row['Date'];					echo '<dt><a href="', $row['Website'], '" >', $row['Name'], '</a> - ', DATE_FORMAT($linkdate, '%a'), '</dt>'; //here's where i'd like the date					echo '<dd>', $row['Description'], '</dd>';				echo '</dl>';				echo '</div>';		echo '<a class="contentBack" href="', $row['Website'], '" style="background-image:url(', $row['Image'], ')"></a>';		echo '</div>';	}	mysql_free_result($result);	mysql_close();?>

Link to comment
Share on other sites

Arrays have nothing to do with it. The only questions are what kind of data you're starting with and how you want it to look. I can't give much advice since I don't know the answer to either of those.Have you read what the manual says about date_format?

Link to comment
Share on other sites

Arrays have nothing to do with it. The only questions are what kind of data you're starting with and how you want it to look. I can't give much advice since I don't know the answer to either of those.Have you read what the manual says about date_format?
my $row['Date'] variable should be the date attribute from my database, which is a datetime data type. i'd like it to just display the date in this format: Sun, Jul 24 2011. not sure why the error i get says it's looking for datetime when it should already be in that data type.
Link to comment
Share on other sites

have you verified that by actually checking the value before using it?

var_dump($row['Date']);

what does that output?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...