How could I write a If statement in Excel to divide a cell by 2088 if it is a leap year, and if it is not a leap year divide the same cell by 2080?
If you put this in A2:
=IF(OR(MOD(A1,400)=0,AND(MOD(A1,4)=0,MOD(A1,100)<>0)),2088, 2080)
And then put the year you care about in A1 and your value in B1 and then do:
=B1/A2
See this Technet article for further info (I used the IF statement from there as a base).
Edit: Or do you mean that you want to divide the year by that value? If so add the following in any cell but A1:
=IF(OR(MOD(A1,400)=0,AND(MOD(A1,4)=0,MOD(A1,100)<>0)), A1 / 2088, A1 / 2080)
And put the year in A1.
In GREGORIAN CALENDAR most years which are multiple of 4 are leap years.
But three leap years are omitted every 400 years.
So in order to be a leap year, the year should be divisible by 4 except the centennial years, which are not divisible by 400.
for eg. 2000 was a leap year but 2100,2200 and 2300 will not be.
And to be more precise check this link
http://support.microsoft.com/kb/214019
Related
I want to count say how many Mondays we have from 2022-02-01 - 2022-03-01. I found smth like this:
=SUMPRODUCT(WEEKDAY(B4:C4)=2) - B4 and C4 are the dates
But it returns 0. I assume it only checks if specific date is the specific day. Any ideas how I can do this but for a date range? So how count how many Mondays there are in February
I also found this
=NETWORKDAYS.INTL(B4;C4;"1000000")
but this returns 25
You can take advantage of the NETWORKDAYS.INTL function by using the string method to make all the days as weekend except for Monday.
The String method states:
weekends can be specified using seven 0’s and 1’s, where the first number in the set represents Monday and the last number is for Sunday. A zero means that the day is a work day, a 1 means that the day is a weekend. For example, “0000011” would mean Saturday and Sunday are weekends.
In this case since you only want to know the Mondays, the string would be "0111111" and the function would look like:
=NETWORKDAYS.INTL(StartDate,EndDate,"0111111")
I think this is right. It's counting inclusively so you would get five Mondays starting on Monday 7th Feb 2022 and ended on Monday 7th March 2022 for example.
=floor((B2-(A2+7-weekday(A2,12)))/7)+1
where A2 and B2 contain the start date end end date.
Obvs nul points for me again but for the record this could be generalised if you put the day number in C2 (e.g. 1 if you want to find Sundays, 2 for Mondays):
=floor((B2-(A2+7-weekday(A2,10+C2)))/7)+1
I have the year a car was purchased in column A. For example, 2015. I'm trying to calculate the age of the vehicle comparing the year provided in column A to TODAY() in an arrayformula, like this...
={"Vehicle Age";arrayformula(if(A2:A="",,(datedif(A2:A,today(),"Y"))))}
For some reason, it gives me the number 115 as the result for every cell where a year has been specified. Any idea why? I can't seem to find an answer on this anywhere on the internets.
Thanks for your help!
You are mixing apples and oranges here, so to speak.
Internally, Google Sheets sees all full dates as a number of days from an origin point of December 31, 1899. As such, the year 2015 on its own, in a comparison with a full date will be seen as two-thousand-fifteen days since December 31, 1899 (or July 7, 1905 — which was 115 some-odd years ago, as would be the case with any relatively recent year, because they'll all be interpreted in their raw form by Sheets as a cluster of days from late June to early July of 1905).
Instead, you want to compare the years only, which will mean extracting the year from TODAY(), since A2:A are already year-only numbers:
={"Vehicle Age";arrayformula(if(A2:A="",,year(TODAY())-A2:A))}
However, since any year's car models are actually released the year before, you may want to add a year to your formula:
={"Vehicle Age";arrayformula(if(A2:A="",,year((TODAY())-A2:A)+1))}
Of course, you could also have turned your A2:A years into real dates (e.g., January 1 of each year listed) and then used datedif as well:
={"Vehicle Age";arrayformula(if(A2:A="",,datedif(DATE(A2:A,1,1),today(),"Y")))}
... or with that extra year added ...
={"Vehicle Age";arrayformula(if(A2:A="",,datedif(DATE(A2:A,1,1),today(),"Y")+1))}
={"Vehicle Age";arrayformula(if(A2:A="",,datedif(DATE(A2:A,1,1),today(),"Y")))}
Not working
I need to count a number of occurrences for each day in a month, but the formula must not include month and year because I need to reuse it every month.
I have a table with rows and columns like this:
1 2 3 4 5 6 7 8 ... 31
Under each of these dates I need to inserted the counted number of occurrences for that day of the month.
Try,
=sumproduct(--(day($B2:$B)=E1))
I happened to have some dates lying around. Here's a sample.
Linked spreadsheet
I'm trying to create a week on week comparison in Google Sheets.
The nuance is that the Comparison Week needs to dynamically populate as the corresponding week of the previous month.
So if the dataset is the first week of May, the Comparison Week would be the first week of April. Likewise, week 2 of May would be compared to week 2 of April, etc.
As an example, if A1 is 5/1/2016 and A2 is 5/7/2016, cells B1 and B2 should populate as 4/3/2016 and 4/9/2016 respectively (where Sunday is the first day of the week).
I've built the following formula which I think gets me about halfway:
=WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),MONTH(A1),1),1)+1
This formula returns the week number in the month from a given date. For example, 5/1/2016 returns the value '1' because the date occurs on the first week of the month. 5/8/2016 would return '2', etc.
Use formula below. It looks ugly, but it should work exactly as your example.
As an example, if A1 is 5/1/2016 and A2 is 5/7/2016, cells B1 and B2
should populate as 4/3/2016 and 4/9/2016 respectively (where Sunday is
the first day of the week).
=DATE(YEAR(A1),MONTH(A1)-1,DAY(A1)+IF(WEEKDAY(A1-DAY(A1)+1)=1,8,WEEKDAY(A1-DAY(A1)+1))-WEEKDAY(DATE(YEAR(A1),MONTH(A1)-1,1),1))
here is how it works
=DATE(
YEAR(A1),
MONTH(A1)-1,
return date of previous month with day calculated as follows:
DAY(A1)
start at the current date
+IF(WEEKDAY(A1-DAY(A1)+1)=1,8,WEEKDAY(A1-DAY(A1)+1))
find out what day is the first day of the current month and add its number. Only if it is Sunday (1st day of week) it needs to skip week 0 so it adds 8
-WEEKDAY(DATE(YEAR(A1),MONTH(A1)-1,1),1)
deduct number representing first day of previous month
So for example if you have 5/3/2016 it does:
(3rd day of month) + (first day of current month in Sunday, so add 8) - (first day of previous month is Friday, so it deduct 6)
3 + 8 - 6 =5 and this is day of previous month, so result is 4/5/2016
If I have week 7 in 2017 what week date is the Monday in that week in Google Sheets?
=DATE(B9,1,1)-WEEKDAY(DATE(B9,1,1),3)+7*(WEEKDAY(DATE(B9,1,1),3)>3)+7*(A9-1)
is the least complicated formula I know which works for week numbers in Sweden (i.e. Monday first day of week, ISO rules for what is week 1).
Short answer (A1==Week, B1==Year):
=DATE(B1;1;1)+((A1-1)*7)-WEEKDAY(DATE(B1;1;1);3)
Long answer:
DATE(<year>;1;1) // days since 1970 until the frist day of the year
plus
((<week number>-1)*7) // how many days into the year is this week
minus
WEEKDAY(DATE(<year>;1;1);3) // how many extra days from previous year in first week
PS:
This assumes monday as the first day of week you have to change the arguments for WEEKDAY to change it to sunday
Because of this definition (https://en.wikipedia.org/wiki/Week) the 4th of January must be used instead the 1st. The 4th of January is the first day which is always in the week 1.
=DATE(B1;1;4)+((A1-1)*7)-WEEKDAY(DATE(B1;1;4);3)
If you are using ISO weeks, the accepted answer doesn't account for weeks overlapping on 2 technical years like 2020-w53, which is from 28 Dec 2020 until 3 Jan 2021.
Therefore I'm using this formula instead:
=DATE(K2,1,1)-WEEKDAY(DATE(K2,1,1),2)+7*(WEEKDAY(DATE(K2,1,1),2)>3)+7*(L2-1) +1
Where K is the Year, and L is the Week number (split in 2 columns from yyyy-ww)
to have it in an arrayformula:
=ArrayFormula(if(K2:K="",, DATE(K2:K,1,1)-WEEKDAY(DATE(K2:K,1,1),2)+7*(WEEKDAY(DATE(K2:K,1,1),2)>3)+7*(L2:L-1) +1 ))
You can use =ArrayFormula(if(E2:E="",,split(E2:E,"-"))) to split yyyy-ww in two columns.
NOTE: This formula would return the Monday (Which is the first day of the week in international standard, ISO)
Worked this up for 2023. It will work through end of 2024 too .. that said the AND logic is flawed .. feel free to suggest something to make this better
=IFS(
AND(ISOWEEKNUM(A8)=52,YEAR(A8)<>YEAR(A7)),
DATE(YEAR(A8-1),1,1)-WEEKDAY(DATE(YEAR(A8-1),1,1),3)+7*(WEEKDAY(DATE(YEAR(A8-1),1,1),3)>3)+7*(ISOWEEKNUM(A8)-1),
DATE(YEAR(A8),1,1)-WEEKDAY(DATE(YEAR(A8),1,1),3)+7*(WEEKDAY(DATE(YEAR(A8),1,1),3)>3)+7*(ISOWEEKNUM(A8)-1)
)