EffectiveWay To Store Date Definitions

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
lightnb
Forum Newbie
Posts: 13
Joined: Mon Jul 28, 2008 11:13 pm

EffectiveWay To Store Date Definitions

Post by lightnb »

I need a table to store the 'definition' of dates (not an actual date).

For example, "First and third Friday of every month", "The 25th of December", "Every Monday and Wednesday", and "The last Sunday of February".

They need to be stored in such a way that a script can easily pull out the rules and see if today matches any of them.

Any Ideas?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: EffectiveWay To Store Date Definitions

Post by onion2k »

You need four parts for each rule - the day it falls on, the frequency at which it occurs, and the start and end points. Each rule should only deal with 1 period at a time. Eliminate any rules like "First and third Friday of every month" ... that should be two different rules, one for the 1st Friday and one for the 3rd Friday. Based on that it should be fairly straightforward to define a set of criteria for every eventuality and design a schema to hold all the necessary rules. It'll be a heck of a lot of work mind you. Good luck.

I would also suggest you read the RFC for the iCalendar format... http://www.ietf.org/rfc/rfc2445.txt It's pretty complicated stuff but it might help.
Post Reply