July 15, 2022 at 9:55 am
Hi guys
Could you please help me to build a calendar in SQL, with the normal holidays from Portugal. Is this possible?
Or....is there any chance of getting the holidays from Portugal for a specific year (2019-2022). I looked everywhere but i must be looking the wrong places....
Thank you all very much for helping me
Pedro
July 15, 2022 at 12:12 pm
Hello Phil
This is amazing!!Exactly what I needed
It's amazing how you guys always come up with such an easy answer.
Thank you soooooo much Phil!!
July 15, 2022 at 12:12 pm
Or....is there any chance of getting the holidays from Portugal for a specific year (2019-2022).
Most internet calendars have details of public holidays now a days, so I would expect there to be a wealth of sites that list them. A search gave me a lots of sites and the first 2 (1, 2) seemed promising; are they missing critical information you need?
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
July 15, 2022 at 1:11 pm
Hi Tom,
Thank you very much for your answer. Phil already answered this one.
Also, now i know what was my "problem" not finding those calendars: i did the search in portuguese
Thanks a lot Tom
July 15, 2022 at 3:54 pm
Here's another listing that not only lists the fixed holidays that always occur on the same day of every year but also how to calculate the "movable" holidays.
https://en.wikipedia.org/wiki/Public_holidays_in_Portugal
Here's one of the easiest functions I've found to calculate Easter day with. BEFORE YOU USE IT... you should convert it to an Inline Table Valued Function (iTVF)
https://weblogs.sqlteam.com/peterl/2010/09/08/fast-easter-day-function/
Ya just gotta love the people that break down the math for the rest of us.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 15, 2022 at 4:04 pm
Hello Jeff
In fact it's impossible not to love those guys.
Thanks a lot for your message
Best regards
Pedro
July 15, 2022 at 5:18 pm
Shifting gears a bit, I remembered that I had refactored Peter's good code and found it in my archives. I redacted that to have a nice flower box and included the original date of Peter's code and my original redaction.
So, here's an "Easter Day" function already converted to an iTVF complete with a usage example.
CREATE OR ALTER FUNCTION dbo.GetEasterDate
/****************************************************************************************
Purpose:
Given a 4 digit year from 1900 thru 9999, return the date of Easter Sunday.
-----------------------------------------------------------------------------------------
Usage Example;
SELECT edt.EasterDate
FROM dbo.SomeTable st
CROSS APPLY dbo.GetEasterDate(DATEPART(yy,st.SomeDateTimeColumn)) edt
;
-----------------------------------------------------------------------------------------
Reference:
Based on the work of Peter (Peso) Larsson, which can be found at the following URL:
https://weblogs.sqlteam.com/peterl/2010/09/08/fast-easter-day-function/
-----------------------------------------------------------------------------------------
Revision History:
Rev 00 - 08 Sep 2010 - Peter Larsson
- Initial release and unit test.
Rev 01 - 16 Feb 2013 - Jeff Moden
- "Modenize" the code to avoid string conversions
****************************************************************************************/
(@Year SMALLINT)
RETURNS TABLE AS
RETURN
SELECT EasterDate = DATEADD(dd,DATEDIFF(dd,0,DATEFROMPARTS(@Year,c.MM,c.DD))/7*7,6)
FROM (VALUES
( 0,04,15)
,( 1,04,04)
,( 2,03,24)
,( 3,04,12)
,( 4,04,01)
,( 5,04,19)
,( 6,04,09)
,( 7,03,29)
,( 8,04,17)
,( 9,04,06)
,(10,03,26)
,(11,04,14)
,(12,04,03)
,(13,03,23)
,(14,04,11)
,(15,03,31)
,(16,04,18)
,(17,04,08)
,(18,03,28)
) c (Cycle,MM,DD) --MM and DD are the yearless "Base Date" of each "Cycle"
WHERE @Year BETWEEN 1900 AND 9999
AND c.Cycle = @Year%19 --Easter dates are on a 19 year cycle since 1900
;
--Jeff Moden
Change is inevitable... Change for the better is not.
July 15, 2022 at 6:20 pm
Very good Jeff. Such a valuable information!!
Thank you so much
Have a great weekend!
Pedro
July 15, 2022 at 8:55 pm
You bet. Thank you for the feedback, Pedro.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 10 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy