Jump to content

want to add 5 days to NOW()


bradkenyon

Recommended Posts

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?

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/119291-want-to-add-5-days-to-now/
Share on other sites

??

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

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.

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.'; 
}
?>

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.