Jump to content

future dates


poe

Recommended Posts

my table has:

 

id | user | month | year

1 | chris | 6 | 2006

2 | chris | 12 | 2006

3 | chris | 1 | 2007

4 | mary | 6 | 2007

5 | mary | 11 | 2007

6 | chris | 8 | 2007

7 | chris | 9 | 2007

8 | chris | 1 | 2008

9 | chris | 4 | 2008

 

 

how do i select just the records that belong to a certain user 'chris' that are months in the future so since 2006 has passed,  id 1, id 2 will be skipped, id3 will also skip

 

 

Link to comment
Share on other sites

It would be easier if you used a date data type instead.. but since you've got integers (are they integers?  or varchars?), you can do

 

$cur_month = date('m');
$cur_year = date('Y');
$sql = "SELECT * FROM table WHERE user = 'chris' AND (year > $cur_year OR (month > $cur_month AND year = $cur_year))";

 

You can also fetch the date from within mysql, but I'm not familiar with how to do that.

 

Edit: Oops.. fixed silly mistake

Link to comment
Share on other sites

  • 2 weeks later...
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.