Solved

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

Posted on 2013-06-14
6
480 Views
Last Modified: 2013-06-14
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
Comment
Question by:Neil Thompson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 39247216
0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 39247221
A sample query might go something like this...
$then = date('c', strtotime('now - 30 minutes'));
$sql = "SELECT ... WHERE addition_time <= '$then' ORDER BY...";
0
 
LVL 57

Accepted Solution

by:
Julian Hansen earned 250 total points
ID: 39247315
This can be done in MySQL like so
SELECT * FROM yourtable WHERE entrytime < NOW() - INTERVAL 30 MINUTE;

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Closing Comment

by:Neil Thompson
ID: 39247519
Many thanks these 2 tips worked a treat
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39247537
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
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 39247718
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question