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
date less than
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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
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
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
-
bob_the _builder
- Forum Contributor
- Posts: 131
- Joined: Sat Aug 28, 2004 12:25 am
At the moment I have:
To try and acheive as explained above.
Thanks
Code: Select all
$sql = mysql_query("SELECT * FROM calendar WHERE DATE_ADD(NOW(), INTERVAL 1 DAY) = starttime && sendemail = 1");Thanks
-
blackbeard
- Forum Contributor
- Posts: 123
- Joined: Thu Aug 03, 2006 6:20 pm
Try this:bob_the _builder wrote:At the moment I have:
To try and acheive as explained above.Code: Select all
$sql = mysql_query("SELECT * FROM calendar WHERE DATE_ADD(NOW(), INTERVAL 1 DAY) = starttime && sendemail = 1");
Thanks
Code: Select all
$sql = mysql_query("SELECT * FROM calendar WHERE starttime BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 6 HOUR) AND sendemail = 1");