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
https://forums.phpfreaks.com/topic/41914-future-dates/
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
https://forums.phpfreaks.com/topic/41914-future-dates/#findComment-203239
Share on other sites

  • 2 weeks later...

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.