Jump to content

Recommended Posts

Does anybody know where I can find a good tutorial for converting dates?

 

Assuming you're referring to PHP - date and strtotime.

 

What I am trying to do is is have mysql only show entries from a certain time frame.

 

Are your dates stored in the database as 'DATE' or 'TIMESTAMP'?

You are better off storing them either as type date or a unix timestamp. The benefit of timestamps is that they are quite versatile, and easy to compare. The benefit of date is that there are a number of mysql (if that's what you are using) date functions that you can use, making it easy to optimize some queries whereas with a timestamp you would need to pull the data from the database and then process it after.

ok, got it to subtract the dates but for some reason I cannot get get stuff to show.  here is what I have so far:

 

$shownews = mktime(0, 0, 0, date("m"), date("d")-5, date("y"));
$getnews = date("m/d/y", $shownews);


$mysql = mysql_connect("localhost", "*****", "****");
mysql_select_db("******", $mysql) or die(mysql_error());
$resultsn = mysql_query("SELECT * FROM news where ndate >= $getnews")
or die(mysql_error());
while($rowsn = mysql_fetch_array( $resultsn )) {
?>
<div style="padding-left:33px;padding-top:20px;"><?php echo $rowsn['ndate']; ?></div>
<div style="padding-left:33px;padding-top:10px;padding-right:25px;"><?php echo $rowsn['nstxt']; ?></div>
<div style="padding-left:33px;padding-top:10px;padding-right:25px;"><?php

$extnews = nl2br($rowsn['nltxt']);

echo $extnews; ?></div>
<div align="center"><img src="images/line.gif" vspace="7" width="223" height="2"></div>

<?php
}

 

But for some reason it is showing all of the entries not just the ones for the past 5 days.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.