|
-
Apr 13th, 2009, 02:52 PM
#1
Thread Starter
Lively Member
[RESOLVED] working with dates
Hi
I'm pretty new to php & mysql and am looking help with a problem I have with dates. Here is some code I am using:
Code:
$result = mysql_query("
SELECT date_format(`ItemPubDate_t`,'%H:%i %d %b %y'), ItemTitle,ItemLink,ItemSourceURL
FROM feedItems WHERE `ItemPubDate_t` >=
DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 60 MINUTE)
ORDER BY `ItemPubDate_t` DESC LIMIT 30", $connection);
if(!$result) {
die("Database selection failed: " . mysql_error());
}
If ($row = $result){
echo "New feeds added within last 1 hour<br/ >";
while ($row = mysql_fetch_array($result)){
echo "<tr><td>$row[0] <A href=$row[2]>$row[1]</A></td></tr>";
}
}
I have a table in the mysql database that has a list of rss feeds that updates frequently. I am trying to display on my webpage feeds added within the last 1 hour. The problem is, when I use the above code, it displays feeds added within the past 2 hours. From some brief research, it would appear (now please correct me if I am wrong) my server time is in UTC which is 1 hour behind BST which I want which is the problem.
Can anyone help me sort this problem?
Thanks
Damian
Last edited by rocket0612; Apr 13th, 2009 at 02:58 PM.
The Box Said: "You need Windows Vista or better" ... So I Installed LiNUX 
-
Apr 13th, 2009, 04:51 PM
#2
Re: working with dates
well, if you're subtracting 60 minutes from the current timestamp and are getting the last 2 hours (instead of the last 1 hour), couldn't you just get rid of the DATE_SUB call and use the current timestamp? that should, if I'm not mistaken, give you the result you want.
oh, and I was just wondering; why do you have an IF statement defining $row as $result?
Last edited by kows; Apr 13th, 2009 at 04:54 PM.
-
Apr 13th, 2009, 05:26 PM
#3
Thread Starter
Lively Member
[RESOLVED] Re: working with dates
 Originally Posted by kows
couldn't you just get rid of the DATE_SUB call and use the current timestamp?
Thanks, I see what u mean
 Originally Posted by kows
oh, and I was just wondering; why do you have an IF statement defining $row as $result?
Have just been learning both php & mysql and thoughy I'd copied exactly what was on a tutorial from lynda.com, but having checked it, I see I copied it in error.
Thanks alot for your help, it is greatly appreciated.
The Box Said: "You need Windows Vista or better" ... So I Installed LiNUX 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|