Jump to content

Recommended Posts

I need a query that will only pull today's events out of the db table.

 

I have a field that stores dates, titled: expiredate

 

for example, an event that i want to display today has a expiredate of: 2008-08-19 19:21:00

 

I just want it to check for 2008-08-19

 

So any events w/ a expiredate of 2008-08-19 will be displayed.

 

Obviously it will check for 2008-08-20 tomorrow, so I just want the query to check for the event's YYYY-MM-DD and if it is equal to the current YYYY-MM-DD, then pull it.

 

I was thinking of something like.

 

SELECT * table WHERE expiredate(YYYY-MM-DD) = CURDATE(YYYY-MM-DD)

 

The above query is literal, so you can see what I am trying to achieve.

 

Any help is appreciated.

 

Thanks.

SELECT * FROM upcomingevents WHERE DATE(expiredate) = CURDATE()

I wonder if mysql will still use the index if you leave out the DATE() function and just let MySQL deal with the casting... as written, it definitely won't... maybe I'll go check.

I need to check for YYYY-MM-DD of expiredate and current date, and not factor in the hour, min, secs.

 

This seems to not work:

 

SELECT * FROM upcomingevents WHERE DATE(expiredate) = CURDATE()

 

I was thinking this may do it, but it did not:

 

SELECT * FROM upcomingevents WHERE DATE(expiredate, '%Y-%m-%d') = DATE_FORMAT(CURDATE(),'%Y-%m-%d')

this is what I have, I have an event for today: 2008-08-20, and it does not display it, but if I have this

$query = "select * from upcomingevents WHERE expiredate LIKE '$today %'";

, it does.

 

and this does not:

<?php
$query = "SELECT * FROM upcomingevents WHERE DATE(expiredate) = CURDATE()";

$result=mysql_query($query);
if($result)
{
	?> <ul> <?php
	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';
?>

 

 

The query with date(...) = curdate() should be working unless curdate() is not what you think it is. Try the following query -

 

SELECT CURDATE()

 

Also, how are you forming the $today variable in your query that does work?

 

My guess is the time zone set on your mysql server is not what you expect.

Stupid me put the format of the datetime as 2008-08-22 09:17:00

 

it should be 20080822091700

 

So $today = 2008-08-22 and it checks the year-month-day part of the expiredate, which does the trick.

 

next time i'll format it correctly.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.