user2178637
user2178637

Reputation: 117

comparing entered date with database date except year

I have a table months -

create table months (mid int(10), month varchar(12)); 

in mid column i have given 1 to 12 numbers and months January to December

and other table allocate , i have 33 colums

mid - reference key for **months** table
product_id - comes from url

columns day1 to day31 to store the days for every month on the particular product according to product_id.

User enters the date in yyyy-mm-dd format. If i exclude year it will become mm-dd format, this i want to compare with database date. But there it is day1 to day31 for days. How can i compare these two dates

I am not getting how this can be done

Upvotes: 0

Views: 177

Answers (1)

Hart CO
Hart CO

Reputation: 34784

I'd strongly suggest altering your table structure to make use of date datatypes, as well as normalizing it (ie not having 31 columns to represent day of month).

If you want to extract the Month, 1-12 from a date field, use MONTH(), likewise DAY() for day.

Otherwise you'll be breaking the user supplied date apart and have to use dynamic queries to point to the intended field.

I can't tell from the question what you need exactly, and how the data is being used, but I see mention of Product_ID. So perhaps you need something like:

YourTable (ProductID, Date, Value)

The year can always be the same if it's irrelevant in your data. Instead of having 31 day fields you'd just have multiple rows, ie:

ProductID Date         Value
1         19000501     5
1         19000502     9
1         19000503     4

If you add some context on what you're storing and how you're using it I'm sure we can come up with a table structure that makes sense.

Upvotes: 1

Related Questions