Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help with selecting records in past 24 hours.
Old 11-06-2010, 04:20 PM Help with selecting records in past 24 hours.
Skilled Talker

Posts: 53
Trades: 0
Hey all, Im just having some trouble with some code. I'm trying to select all records from a mysql database between now and 24 hours ago. What I have so far is.

$get = mysql_query("SELECT * FROM teams WHERE section='$sec' AND date_time_added < NOW() ORDER by id DESC LIMIT $start, $per_page");

I just dont know how the syntax should be structured to select between "NOW" and 24 hours ago.

-Worldy
worldy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-06-2010, 04:43 PM Re: Help with selecting records in past 24 hours.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Try,
SELECT * FROM teams WHERE date_time_added < DATE_SUB(NOW(), INTERVAL '24' HOUR)


Credits:
Knowledge previously inherited by Chrishirst & forcing me to learn more SQL.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE



Last edited by lynxus; 11-06-2010 at 04:44 PM..
lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 11-06-2010, 06:57 PM Re: Help with selecting records in past 24 hours.
Skilled Talker

Posts: 53
Trades: 0
Okk I gave that a try, but it gives me results from 24 hours hours onward, instead of between 24 hours and now.
worldy is offline
Reply With Quote
View Public Profile
 
Old 11-07-2010, 05:05 AM Re: Help with selecting records in past 24 hours.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Sorry change:
SELECT * FROM teams WHERE date_time_added < DATE_SUB(NOW(), INTERVAL '24' HOUR)

to

SELECT * FROM teams WHERE date_time_added > DATE_SUB(curdate(), INTERVAL 1 DAY)
or
SELECT * FROM teams WHERE date_time_added > DATE_SUB(curdate(), INTERVAL '1' DAY)
or
SELECT * FROM teams WHERE date_time_added > DATE_SUB(NOW(), INTERVAL '1' DAY)
or
SELECT * FROM teams WHERE date_time_added > DATE_SUB(NOW(), INTERVAL 1 DAY)


All 4 of the above should work, However try them from top to bottom.
you can try changing curdate() to now() but the above should work ( seems to work here )
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE



Last edited by lynxus; 11-07-2010 at 05:07 AM..
lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 11-07-2010, 12:54 PM Re: Help with selecting records in past 24 hours.
Skilled Talker

Posts: 53
Trades: 0
Thanks It works!
worldy is offline
Reply With Quote
View Public Profile
 
Old 11-07-2010, 01:48 PM Re: Help with selecting records in past 24 hours.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Quote:
Originally Posted by bradtraversy View Post
Hi

well one simple way could be such as:

SELECT * FROM `log` WHERE `time` > UNIX_TIMESTAMP() - 3600 * 12

SELECT * FROM `log` WHERE `time` > UNIX_TIMESTAMP() - 3600 * 24

SELECT * FROM `log` WHERE `time` > UNIX_TIMESTAMP() - 3600 * 36




Thanks
Problem here being the unix timestamp can be different to the DB timestamp.. So its not the most reliable.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Reply     « Reply to Help with selecting records in past 24 hours.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26008 seconds with 12 queries