0

I am currently working on a project in which I want to store commemorative days (like January 8th's World Leprosy Day) in a database. At this moment they're stored in a table which contains:

- an ID
- the date as varchar (stored European style, e.d. "8-01" for January 8th)
- length of the commemorative day (as some span multiple days)
- and the name

The reason I am storing the date as varchar is because the year is irrelevant, and I'm a bit reluctant to just store a year (e.g. 2013) in the database and truncate it.

But here's the problem: I can't seem to find a way to construct a query that will get the rows between dates. I think it's because the way the dates are stored in the database.

I already tried (given day = "8-01") SELECT * FROM comdays WHERE date(day) BETWEEN date("1-01") AND date("20-01")

But to no avail.

Is there a way to get this thing going with strings? Or do I have to change the date column into a MySQL DATE format?

Thanks in advance!

4

1 回答 1

0

如果您真的想在 MYSQL 中保留非标准日期字段,您将需要使用以下格式0108->mmdd这种格式允许计算。

可能还值得阅读以下类似问题的答案Save day and month in database

于 2013-11-12T16:04:14.847 回答