I’m writing some fields about some events in my database and I was thinking that I can do with:
rangeType (varchar) (may be: daily, weekly, monthly, yearly)
rangeStart (datetime)
rangeEnd (datetime)
I want to match a record when NOW() is in the range of time:
-
when
rangeTypeis'yearly', if date ofNOW()is between the month+days ofrangeStartandrangeEnd -
when
rangeTypeis'monthly'ifNOW()is between the days ofrangeStartandrangeEnd -
when
rangeTypeis'weekly'ifNOW()is…. -
when
rangeTypeis'daily'if the time ofNOW()is….
I think weekly needs a special treatment here, and the overall structure is not so flexible…
Then I need more fields! but I want something easy to read and mantain… what is the best way to do this with MySQL? Is there some function that allows me to do this without writing and mantain rows and rows of SQL?
What about the ISO8601 period specification?
Something like this?