dgrafx
asked on
calculating calendar holidays
I want to add US holidays to a calendar from events stored in database
Some examples:
Mothers Day = 2nd Sunday in May
Fathers Day = 3rd Sunday in June
Thanksgiving = 4th Thursday in November - Not the last Thursday cause it may have 5 some years
etc
I need ideas on what is best solution to calculate
Some examples:
Mothers Day = 2nd Sunday in May
Fathers Day = 3rd Sunday in June
Thanksgiving = 4th Thursday in November - Not the last Thursday cause it may have 5 some years
etc
I need ideas on what is best solution to calculate
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Be careful with functions. They slow down query performance. I'd go with @Jim table.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
How would a person go about querying for holidays in a setup like Jims or a smaller such table?
the intention to use function in this scenario is to find the specific date of a holiday with a predetermined pattern, of course when we are doing a more complex query, the function will slow down the overall performance, and as other experts suggested, to store those holidays into a table for references could be a better approach if we are knowing those specific holidays at the first place.
>>How would a person go about querying for holidays in a setup like Jims or a smaller such table?
just treat the holidays are stored in a table, so we can use a Select SQL statement to pull out the relevant records accordingly but this depends on how we design the table.
>>How would a person go about querying for holidays in a setup like Jims or a smaller such table?
just treat the holidays are stored in a table, so we can use a Select SQL statement to pull out the relevant records accordingly but this depends on how we design the table.
ASKER
Can you give an example using Mother's Day or Father's Day so I can see what you're referring to?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
My comment with functions, it's ok to use them. But if you are trying to check many holidays and the like, doing it in real time hurts performance. it might not be a very big issue for your scenario. But just keep in mind that a function is optimised differently from using (a set based method such as) a JOIN for example. If you have small datasets, it's fine. You won't notice. but if you have a large dataset, the function method might be a little slower.
ASKER
Thanks a lot guys
I created my own smaller table and populated it with several years of holidays - using functions to calculate the dates for each year and inserted static holidays as well.
I now can union this along with the user created events.
I can see now that this was the way to go.
Thanks!!!
I created my own smaller table and populated it with several years of holidays - using functions to calculate the dates for each year and inserted static holidays as well.
I now can union this along with the user created events.
I can see now that this was the way to go.
Thanks!!!