Jump to content

[SOLVED] MySQL help - Date field greater than or equal to today


tqla

Recommended Posts

Hello. I have a date field in my mysql table.

 

The dates in that field are all formatted like this: 2009-01-01

 

I need to count the rows that meet the criteria in my query below PLUS with a date greater than or equal to today?

 

$sql = "SELECT * FROM table WHERE field1 = '1' AND field2 = '0' AND field3 = '1' AND field3 >= (HERE IS WHERE IN NEED TO SAY GREATER THAN OR EQUAL TO TODAY)";

$result = mysql_query($sql) or die (mysql_error());
$numrows = mysql_num_rows($result);

	if($numrows >= 1){

		//I'll put code here if there are one or more rows that meet criteria

		} 

 

Is this possible? How?  ???

Link to comment
Share on other sites

How about making a variable with the current time and date?

 

  $dt2 = date('Y-m-d H:i:s');
$sql = "SELECT * FROM table WHERE field1 = '1' AND field2 = '0' AND field3 = '1' AND field3 >= " . $dt2 . ")";

 

$result = mysql_query($sql) or die (mysql_error());

$numrows = mysql_num_rows($result);

 

      if($numrows >= 1){

       

        //I'll put code here if there are one or more rows that meet criteria

 

        }

Link to comment
Share on other sites

I understand we're after today, not now, so I would try this way actually

 

If it's a unix timestamp:

 

SELECT * FROM blah WHERE field3 >= UNIX_TIMESTAMP(DATE(NOW()));

 

 

If it's datetime or date:

 

SELECT * FROM blah WHERE field3 >= DATE(NOW());

 

 

 

 

Link to comment
Share on other sites

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.