bradkenyon Posted August 12, 2008 Share Posted August 12, 2008 I plan on setting up a script that is run on the server every Monday morning at 8am. I want to only send the events that are within that week. So I was thinking for pulling the appropriate events from the table, I would do this: SELECT * FROM upcomingevents WHERE expiredate > NOW() + 5 days ORDER BY expiredate Obviously the + 5 days part is being literal, how would I go about adding 5 days to it, meaning I want to send all events that are taking place between Monday 8am to Friday 11:59pm of that week? Quote Link to comment https://forums.phpfreaks.com/topic/119291-want-to-add-5-days-to-now/ Share on other sites More sharing options...
adam84 Posted August 12, 2008 Share Posted August 12, 2008 ?? you may need to put quotes around the date, I dont know though, I ahvent tested it. SELECT * FROM upcomingevents WHERE expiredate > DATE_ADD(NOW(), INTERVAL 5 DAY)) ORDER BY expiredate http://russell.dyerhouse.com/cgi-bin/article.cgi?article_id=45 Quote Link to comment https://forums.phpfreaks.com/topic/119291-want-to-add-5-days-to-now/#findComment-614714 Share on other sites More sharing options...
akitchin Posted August 12, 2008 Share Posted August 12, 2008 he's got a spare closing parenthesis - just make sure you kill it before running that. SELECT * FROM upcomingevents WHERE expiredate > DATE_ADD(NOW(), INTERVAL 5 DAY) ORDER BY expiredate for future reference, MySQL has a wealth of really handy functions. having a look at that part of the manual will be very helpful for future endeavours. Quote Link to comment https://forums.phpfreaks.com/topic/119291-want-to-add-5-days-to-now/#findComment-614745 Share on other sites More sharing options...
adam84 Posted August 12, 2008 Share Posted August 12, 2008 Sorry for the extra ')' he's got a spare closing parenthesis - just make sure you kill it before running that. My bad Quote Link to comment https://forums.phpfreaks.com/topic/119291-want-to-add-5-days-to-now/#findComment-614755 Share on other sites More sharing options...
akitchin Posted August 12, 2008 Share Posted August 12, 2008 everyone misses stuff, especially when writing quick solutions for users - just wanted to avoid him coming back with that error and send him on his way faster. Quote Link to comment https://forums.phpfreaks.com/topic/119291-want-to-add-5-days-to-now/#findComment-614758 Share on other sites More sharing options...
bradkenyon Posted August 12, 2008 Author Share Posted August 12, 2008 Thanks for the help. Maybe there is a little more to my problem than I thought, here is all the code for what I am trying to accomplish, to only display the events on Monday thru Friday, so I only want to display events for 8/11 - 8/15 of this week (think of NOW() as 8/11). Something must be funny w/ the while loops, because it displays all events that are not past due, and I want it to show events only up till the end of 8/15. <?php require_once("../customemailer/htmlMimeMail.php"); include('../cgi-bin/newsinclude/db.php'); $query = "SELECT * FROM upcomingevents WHERE expiredate > DATE_ADD(NOW(), INTERVAL 5 DAY) ORDER BY expiredate"; $result=mysql_query($query); if($result) { ?> <ul> <? while($row = mysql_fetch_array($result)) { $i = 0; $t = 1; while($i <=0) { print '<p><strong>'.date("l F j, Y",strtotime($row['expiredate'])).'</strong> - <a href="/events/?id='.$row['id'].'">'.$row['subj'].'</a> - <small>'.$row['location'].'</small></p>'; //$message.= date("m/d/y",strtotime($row['expiredate']))."\t".$row['subj']."\t".$row['location']."\r\t\t".$row['body']."\r\r"; $message.= ''.date("l F j, Y",strtotime($row['expiredate']))."\r\r\t".$row['subj']."\r\t".$row['location']."\r\t".$row['body']."\r---------------------------------------------------------------------------------------------------------\r\r"; $i++; $t++; } } $email = '[email protected]'; $mail = new htmlMimeMail(); $mail->setText($message); $mail->setSubject('Faculty/Staff Events'); /** * Sends the message. */ $mail->setFrom($email); //$result = $mail->send(array('[email protected]')); //echo $result ? 'Mail sent!' : 'Failed to send mail'; } else { print 'There are no events.'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/119291-want-to-add-5-days-to-now/#findComment-614763 Share on other sites More sharing options...
akitchin Posted August 12, 2008 Share Posted August 12, 2008 if you're only going for monday-friday of the current week, try checking the week number against the current week number. see DATE_FORMAT() in the MySQL manual for more details on that. the reason you're getting all is because you're telling it to pull anything with an expiredate GREATER than NOW() + 5 days - that is, anything that expires later than 5 days from now. Quote Link to comment https://forums.phpfreaks.com/topic/119291-want-to-add-5-days-to-now/#findComment-614766 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.