• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 524
  • Last Modified:

using php return data from Mysql where datetime column is 30 mins or older

Hi

I'm using PHP to look into my mySQL data and return some for sale items. I want non paying members to NOT see new additions so there is a 30 minute delay for them.

How can I create that in the PHP code please?

an example datetime entry in my datebase is : 2013-06-04 12:34:56

so, a user visiting at 2013-06-04 12:44:56 should not see it yet a visitor coming after 30 mins of the datetime 2013-06-04 14:34:56 can see it.

Neil
0
Neil Thompson
Asked:
Neil Thompson
  • 3
  • 2
3 Solutions
 
Ray PaseurCommented:
A sample query might go something like this...
$then = date('c', strtotime('now - 30 minutes'));
$sql = "SELECT ... WHERE addition_time <= '$then' ORDER BY...";
0
 
Julian HansenCommented:
This can be done in MySQL like so
SELECT * FROM yourtable WHERE entrytime < NOW() - INTERVAL 30 MINUTE;

Open in new window

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Many thanks these 2 tips worked a treat
0
 
Ray PaseurCommented:
Thanks for the points - good question! ~Ray

PS: Take note of the possibilities of time differences between the client and the server, and also the possibility that the MySQL server may have time settings independent of the PHP server.
0
 
Julian HansenCommented:
and also the possibility that the MySQL server may have time settings independent of the PHP server

This is relevant only if the date/time information is originating from the PHP Server.

If the records are being updated with a NOW() or CURRENT_TIMESTAMP action then MySQL server time would be the definitive source and the MySQL approach would be the correct way to search for records.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now