Jump to content

display datetime from an array variable


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 post
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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...