Jump to content

Date?


iamnottheend

Recommended Posts

I save the time of a blog post using NOW(). The db column is formatted as postdate.

 

The time comes out as such.. 2007-03-15 15:35:41

 

I want to format this as day/month/year.

 

I have tried

$postdate = $row['blog_postdate'];
$blog_postdate = date(d-m-Y,$postdate);

 

but i just can't get it going. Am i even using the right fuction?

Link to comment
https://forums.phpfreaks.com/topic/43839-date/
Share on other sites

The second parameter to the date() function needs to be a UNIX timestamp, not an ASCII string. You need to use the strtotime() function to convert the string into a UNIX timestamp:

<?php
$postdate = $row['blog_postdate'];
$blog_postdate = date(d-m-Y,strtotime($postdate));
?>

or just

<?php
$blog_postdate = date(d-m-Y,strtotime($row['blog_postdate']));
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/43839-date/#findComment-212810
Share on other sites

Thanks for the help guys. I came up with the first example of what ken had after mjlogan refered me to strtotime.

 

However it only is returning 0 and not the time.

 

New Code..

 

$sql="SELECT * FROM blog LIMIT 5";
$result = mysql_query($sql) or die(mysql_error());	
	while ($row = mysql_fetch_assoc ($result)) {
	$blog_id[] = $row['blog_id'];
	$blog_title[] = $row['blog_title'];
	$blog_meta = $row['blog_meta'];
	$blog_content[] = $row['blog_content'];
	$blog_postdate[] = date(d-m-Y,strtotime($row['blog_postdate']));

	$smarty->assign("blog_id", $blog_id);
	$smarty->assign("blog_title", $blog_title);
	$smarty->assign("blog_meta", $blog_meta);
	$smarty->assign("blog_content", $blog_content);
	$smarty->assign("blog_postdate", $blog_postdate);
	$smarty->assign("blog_author", "Jason");
	$singlearticle = TRUE;
	}

 

HTML

 

			{section name=blog loop=$blog_title}
			<div class="blog_left">
				<h4>{$blog_title[blog]}</h4>
				{$blog_content[blog]}

				<div class="left">
					Posted by {$blog_author}
				</div>
				<div class="right">
					{$blog_postdate[blog]}
				</div>
			</div>			
		{/section}

Link to comment
https://forums.phpfreaks.com/topic/43839-date/#findComment-212816
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.