Jump to content

[SOLVED] selecting recent records


damian0612

Recommended Posts

Hi

 

I am trying to select records added within the last 15 minutes.  My database has a column called ItemAddedTime which is a datetime field which I am using to try and achieve this.  Here is my query:

 

SELECT ItemAddedTime,ItemTitle,ItemLink,ItemSourceURL,ItemDescription
FROM feedItems_all
WHERE ItemAddedTime >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 15 MINUTE)
ORDER BY ItemAddedTime DESC

 

The problem is, the mysql server runs on GMT, but I'm on BST which is currently 1 hour ahead.  How do I add 1 hour onto the current timestamp so the query will then work?

 

Thanks

Damian

Link to comment
https://forums.phpfreaks.com/topic/156399-solved-selecting-recent-records/
Share on other sites

Hi

 

I would be tempted to stick with one time value on the server and just use CURRENT_TIMESTAMP to set the ItemAddedTime when the record is created.

 

If you just want to keep your current setup :-

 

SELECT ItemAddedTime,ItemTitle,ItemLink,ItemSourceURL,ItemDescription
FROM feedItems_all
WHERE ItemAddedTime >= DATE_ADD(CURRENT_TIMESTAMP, INTERVAL 45 MINUTE)
ORDER BY ItemAddedTime DESC

 

but that is likely to confuse maintenance bods in the future. Further you should code to cope with the time in both summer time and winter time.

 

All the best

 

Keith

Hi

 

Thanks for both replies.

 

I'm unable to make any changes to the server or the database I am querying so I have to work as is.  I'll just have to do some php work in the background after the query has been done to acheive what I need unfortunately!!  :'(

 

Thanks anyhow to both of you.

Hi

 

I have never used this, so no experience of it, but it appears you can change the time zone used by MySQL for your connection:-

 

http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html

 

This might well be the best way to do it.

 

All the best

 

Keith

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.