How to define YYYY-MM columns in MySQL

I have a need to store only YYYY-MM in a table column within MySQL.  What is the best format to use to accomplish this?  This field will be matched against dates entered by users to get a range of dates from the table.  For example, the user enters 2010-02 to 2010-04, I'd like to select
the rows from table that are in and between these dates.

COL1             COL2         ROW
2009-11         value1       0
2009-12         value2       1
2010-01         value3       2
2010-02         value4       3
2010-03         value5       4
2010-04         value6       5

So if user enters range of 2010-02 to 2010-04, I'd return ROWS 3,4,5
mamusciaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tdotCommented:
Hi mamuscia
Unix time stamp
0
mamusciaAuthor Commented:
Can you give me an example of how to use a Unix time stamp for this?
0
tdotCommented:
0
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

mamusciaAuthor Commented:
This article didn't explain the use of unix timestamps.  I changed my table back to use DATE and will simply ignore the DAY part fo the date for my purposes, so that I can use a query that goes after YEAR(col1) and MONTH(col1) to get matches.
0
thedwillCommented:
YYYY-MM
Year = substr(date,0,4)
Month = substr(date,5,2)

Select * from table where substr([datecolumn]0,4) = substr([yourstartdate]0,4) AND  
substr([datecolumn],5,2) >= substr([yourstartdate],5,2) AND
substr([datecolumn],5,2) <= substr([yourenddate],5,2)

datecolumn = the column of the table to reference
yourstartdate = begin date
yourenddate = end date

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mamusciaAuthor Commented:
Duh, thanks.  Sometimes the obvious is not so obvious.
I think I'll use this so I can keep my columns as varchar.
0
thedwillCommented:
Yea - the whole timestamp <--> php <--> mysql datetime is quite code cumbersome sometimes.  I'm sure there is a 'right' way to do it, but sometimes the simpler solutions make more sense than  Convert-In and store - read and Convert back to display...
Thanks
 
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.