Results 1 to 3 of 3

Thread: [RESOLVED] working with dates

  1. #1

    Thread Starter
    Lively Member rocket0612's Avatar
    Join Date
    Feb 2005
    Location
    Belfast, Northern Ireland
    Posts
    95

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.

  3. #3

    Thread Starter
    Lively Member rocket0612's Avatar
    Join Date
    Feb 2005
    Location
    Belfast, Northern Ireland
    Posts
    95

    [RESOLVED] Re: working with dates

    Quote Originally Posted by kows View Post
    couldn't you just get rid of the DATE_SUB call and use the current timestamp?
    Thanks, I see what u mean

    Quote Originally Posted by kows View Post
    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
  •  



Click Here to Expand Forum to Full Width