date less than

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

date less than

Post by bob_the _builder »

Hi,

Can seem to get the correct solution for:

one field in the database is datetime .. 2007-05-14 13:00:00

I want to check for records that have 6 hours or less till the actual date and time match and perform a task, then mark that the task completed.

the marking part isnt a problem.

Whats the best query for this situation?


Thanks
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Might want to read up on the datetime functions

Code: Select all

... WHERE date_column > DATE_SUB(NOW(), INTERVAL 6 HOUR)
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post by bob_the _builder »

Thanks,

Im still not having much luck, always ends up grabing all records after set date rather than records due in the next 6 hours.

So the database holds the following dates (datetime:

2007-05-15 11:00:00
2007-05-15 10:00:00
2007-05-16 05:00:00
... etc

perform a query on the 2007-05-14 for all records matching 2007-05-15 and run a task
next day 2007-05-15 query all rrecords matching 2007-05-16 ... etc

Thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

bob_the _builder wrote:Im still not having much luck, always ends up grabing all records after set date rather than records due in the next 6 hours.
May we see the code?
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post by bob_the _builder »

At the moment I have:

Code: Select all

$sql = mysql_query("SELECT * FROM calendar WHERE DATE_ADD(NOW(), INTERVAL 1 DAY) = starttime && sendemail = 1");
To try and acheive as explained above.

Thanks
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post by blackbeard »

bob_the _builder wrote:At the moment I have:

Code: Select all

$sql = mysql_query("SELECT * FROM calendar WHERE DATE_ADD(NOW(), INTERVAL 1 DAY) = starttime && sendemail = 1");
To try and acheive as explained above.

Thanks
Try this:

Code: Select all

$sql = mysql_query("SELECT * FROM calendar WHERE starttime BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 6 HOUR) AND sendemail = 1");
Post Reply