Jump to content

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

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.