 |
 |
mysql question
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2000
Location: Tempe, AZ
Status:
Offline
|
|
I am working with php and mysql.
I have two columns set up in a database. One is year, the second one is month. For simplicity let's say that they are both integer numbers.
I want to select everything from the database that is for this year and beyond, starting from the current month.
This is what I have so far:
today_year=date("Y");
today_month=date("m");
$query="select * from $db where year>=$today_year and $month=$today_month";
how can I tell the database, that I want everything from the current month in the present year, plus everything for years after?
Thanks,
t
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Why would you store month and year as integers? Store dates as dates, and you get lots of nice query functions that would require lots of logic otherwise.
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status:
Offline
|
|
Web Developer
For discussion of languages, databases, or anything else related to Web deployment
eh?
oh, and what Arkham_c said, about dates
|
|
"Have sharp knives. Be creative. Cook to music" ~ maxelson
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2001
Location: somewhere
Status:
Offline
|
|
Originally posted by t_hah:
I am working with php and mysql.
I have two columns set up in a database. One is year, the second one is month. For simplicity let's say that they are both integer numbers.
I want to select everything from the database that is for this year and beyond, starting from the current month.
This is what I have so far:
today_year=date("Y");
today_month=date("m");
$query="select * from $db where year>=$today_year and $month=$today_month";
how can I tell the database, that I want everything from the current month in the present year, plus everything for years after?
Thanks,
t
SELECT * FROM [table] WHERE (year = 2003 AND month >= 9) or year > 2003
But, you really should just store dates as actual dates. That way, you can just say:
SELECT * FROM [table] WHERE order_date >= '2003-09-01'
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|