Google sheets calculations for dates before 1900 - A possible solution - date

I am trying to do calculations without scripts. A solution can be to sum a far in the future date (31/12/9999) +1 and use that value to do calculations
Cell A1 = 1/2/1872 -> -10.194,00
Cell A2 = 31/12/9999 -> 2.958.465,00
Cell A3 = A1-A2+1 -> 2.948.270,00 -> 01/02/9972
I can adjust the year to a more confortable, year that is distant from edges (99999 and 1900) -> I use as offset 4000 which should preserve original leap year. A4: =DATE(YEAR(A3)-8100+4000;MONTH(A3);DAY(A3)) -> 01/02/5872
at this point I can use A4 to do most of calculations on dates and calculate back any adjusted date by using DATEVALUE()
This does of course take into consideration past dates that have issues with current official calentars; it seems that 19th century is ok.
I haven't tested/ported it to Excel.
Does anybody confirm it works?

the logic of your formula may be correct, but more factors must be considered when playing with the calendar as humanity likes to adjust even the rules of adjustment. here are a few examples:
the longest year in history: 46 BCE (708 AUC) lasting 445 days known as "the last year of confusion" as Ceasar added 3 more months (90 days) so that the next year (45 BCE) would start right after the winter solstice.
the shortest year in history: 1582 CE lasting 355 days where October had only 21 days (4th Oct. was followed by 15th Oct.) but also it depends where you are
because British Empire decided to reinvent the wheel by accepting the "1582-wheel" in the year 1752 CE where September had only 19 days (2nd Sep. was followed by 14th Sep.) resulting the year to have 355 days as well. however, if we are technical, the British Empire also had a year that lasted only 282 days because their "old" new year started on 25 March and not 1 January therefore the year 1751 CE started on 25th Mar and ended on 31st Dec. Turkey, for example, joined the "gregorian train" in 1st Jan 1927 CE after their December of 1926 CE had only 18 days so that year was long only 352 days. the latest country to adopt the gregorian calendar was Saudi Arabia in 2016 CE when they jumped from 1437 AH
the year zero: does not exist. 31st Dec. 1 BCE was followed by 1st Jan. 1 CE
753 AUC = 1 BCE
754 AUC = 1 CE
also, dude who invented this nonsense was born around 1223 AUC (470 CE) so that speaks for itself. this is important because offsetting DATEVALUE needs to be done in such a way that the calculation will not cross 0 eg. not drop bellow -693593:
=TO_DATE(-694324) - incorrect datevalue - 01/01/00-1
=TO_DATE(-693678) - incorrect datevalue - 08/10/0000
=TO_DATE(-693593) - 1st valid datevalue - 01/01/0001
=TO_DATE(35830290) - last valid datevalue - 31/12/99999
it's also worth mentioning that 25th Dec. 200 CE was not Friday on the Roman peninsula because people in that era used 8-day system
there are many calendar systems each with its own set of rules and up to this date there are still countries that do not recognize the gregorian calendar as a standard so if you want to re-live the year 2021 go to Ethiopia where today's 9 Oct. 2022 CE = 29 Mes. 2015 EC on the other hand if you prefer to live in the future try Nepal where today's 9 Oct. 2022 = 23 Ash. 2079 BS

Related

Week Number restarting at 1 every month as per ISO format in Tableau

I am trying to get week numbers ( resetting at 1 for each month) as per ISO format for each month in 2019.For example I am interested in getting
All dates in July 2019: week 1 to 4,
All dates in Aug 2019 : week 1 to 4 and so on.
I first created the calculated field (Week_Number_ISO) to get the overall week number in year 2019.I used the following formula;
DATEPART('iso-week',[ Date]) which works as intended.
To get the monthly week number I used the following formula
INT((DATEPART('day',[Created Date])-DATEPART('iso-weekday',[Created Date])+7)/7)+1.
(Idea was to calculate the date of the first day of each week & then divide by 7 and take the integer part)
As per the ISO format, shouldn't July 29 to 31st be a part of week 4 for July?But the formula is showing it as week 5 for July 2019.I feel I am missing something in the formula or am missing something about ISO week number resetting at 1 for each month.
Can someone help me?
Here is an example of the dates in July 2019 and the associated week numbers.
Why would July 28th-July 31st 2019 be considered week 4?

PowerBI Datesbetween - Line Chart Visualisation

I am trying to plot on a line chart running data for 3 fiscal years. My fiscal year being 30 June and not 31 December
Data for Year 1 [1 July 2015 to 30 June 2016]
Data for Year 2 [1 July 2016 to 30 June 2017]
Data for Year 3 [1 July 2016 to 30 June 2018] This is the current year
The following is what I am hoping to achieve.
3 Year Chart
I am not certain how to achieve this.
I was thinking the following might be of some relevance
Revenue from Start = CALCULATE(Report[Revenue], DATESBETWEEN('Dates'[Date], BLANK(), LASTDATE('Dates'[Date])))
I have had it suggested to set up a new measure "Date2". But I really am not sure how to do this. Also given that I am after a third series would I then need to set up a "Date3"
For Date2 [and Date3 if applicable], how would this/these measures be coded, ie is this logical
Date2 = DATE(2015,07,01)
Date3 = DATE(2016,07,01)
Thanks for any help that can be offered. You will see from my question, I know what I want as an output, but have no idea how to really implement.
I would use the TOTALYTD function, e.g.
Revenue from Start = TOTALYTD ( [Revenue] , 'Dates'[Date] , "30 June 2018" )
This blog post is probably the best description of this and related functions:
https://www.sqlbi.com/articles/time-intelligence-in-power-bi-desktop/

Get same day of week last year Excel formula

Would it be possible to get same day of week last year using Excel? please below example:
Input: Monday 9 Nov 2015 | Output: 10 Nov 2014
Thanks
Simply subtract 52 full weeks with 7 days = 364 days. So if the date is in A1, the formula =A1-364 will get the date exactly 52 weeks before, which is the same day of week in the year before.
To show that it works even for leap years, try the following:
You see the formula date - 364 (=A2-364, =A3-364, ...) always gets the same day of week a year before. That is because it gets the day minus 52 full weeks (52 * 7 days) before. In leap years it gets a different day but the same day of week.
Try this:
=DATE(YEAR(A1)-1,MONTH(A1),DAY(A1))+WEEKDAY(A1)-WEEKDAY(DATE(YEAR(A1)-1,MONTH(A1),DAY(A1)))
It returns the closest date within a week. A1 is the cell with this year's date.

How to subtract two dates in Oracle and extract the year part from the difference?

My typical requirement is that I want to subtract two Dates cast as timestamp. The Minuend (First parameter) is the current date and the Subtrahend(second parameter) is stored separately as DD, MM and YYYY in three columns. The final output should be a discrete year as number. I am playing with something like :
SELECT (TO_DATE('05-DEC-2013') -
CASE LENGTH(CAND_DOB_DD)
WHEN 1 THEN
CAST(TO_DATE('0'||CAND_DOB_DD||'-'||CAND_DOB_MM||'- '||CAND_DOB_YYYY,'DD-MM-YY HH24:MI:SS')
AS TIMESTAMP)
ELSE
CAST(TO_DATE(CAND_DOB_DD||'-'||CAND_DOB_MM||'-'||CAND_DOB_YYYY,'DD-MM-YY HH24:MI:SS')
AS TIMESTAMP) / 365 END YEAR
FROM CANDIDATE
The Year part as Integer will be used for a very sensitive calculation. Please suggest if the above piece of SCRIPT will yield the desired result. Thanks in advance.
For most purposes you could just use the Months_Between() function to determine the number of months between two dates, and then divide by 12 etc.. Note that the number of months is an integer when comparing two dates that have the same day of the month or are both the last day of the month.
This is tricky when it comes to leap years.
Do you count 28th Feb 2015 to 28th Feb 2016 as exactly one year, when 28th Feb 2015 to 29th Feb 2016 is one day longer but plainly is a year?
What about 29th Feb 2016 to 28th Feb 2017, or 28th Feb 2016 to 28th Feb 2017?
Think carefully about these boundary cases, but Months_Between() is likely to be your best choice.

Can a year have 364 days?

Here's a bit of fun.
If we peek at the dotnet source code, the following comment can be found at the head of the file TimeSpan.cs:
...while a year can contain 365 or 364 days
Should I be worried?
I don't know what the source code comment refers to, but there are some more exotic calendars where a year only has 364 days, e.g. a leap week calendar:
A leap week calendar is a calendar system with a whole number of weeks every year, and with every year starting on the same weekday. Most leap week calendars are proposed reforms to the civil calendar, but some - such as the ISO week number calendar - are simply conveniences for specific purposes.
The ISO calendar in question is a variation of the Gregorian calendar that is used (mainly) in government and business for fiscal years, as well as in timekeeping. In this system a year (ISO year) has 52 or 53 full weeks (364 or 371 days).
One advantage is the better divisibility. A year with 364 days can be divided into 13 equal months. Other calendars using such a system are according to Wikipedia:
International Fixed Calendar
Pax Calendar
Perhaps they were talking about the maximum day index in a year when the day index starts at zero?
In general, you should not be too worried. There are some years back in time with much less than 364 days! Basically, the crux is the change from Julian to Gregorian calendars, which happened at differing times at differing locales. In the US, the month of interest is Sep 1752,
jlouis#illithid:~$ cal sep 1752
September 1752
Mo Tu We Th Fr Sa Su
1 2 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
since the US was part of the British Empire at that time, see
http://en.wikipedia.org/wiki/Gregorian_calendar#Adoption
for further explanation.
Aside: This is why you should generally not try to do your own date handling. It is pure pain to get all the intricacies correct.
West Samoa crossed the dateline in 2011, skipping December 30th, going from December 29th directly to December 31st.
So technically they had a 364 day year.
Perhaps they meant 365 or 366 days? As far as I know 364 days in a year is not acceptable.
No it can not. Maybe you should worry. Although the number of integer weeks x days per week = 52 x 7 = 364