Jump to content

Convert Date then subtract days


SkyRanger

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.

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.