I am trying to get the number of days per year between two dates.
The results should look somehow like the following picture
The range between the 2 dates in the 2021 year has 301 days and in the 2022 year has 94 days.
Put this in C2 and copy over:
=MIN(DATE(C1,12,31),$B$2)-MAX(DATE(C1,1,1),$A$2)
Your question isn't entirely easy to understand but what you don't know is in plain sight: Excel represents dates as integer numbers where Jan 1, 1900 is the first day (= 1) and all days from then till now have a unique number. Today is 44261. Tomorrow will be 44262.
Therefore the difference between dates equals [End date] - [Start date], where only one of these two dates is included in the count. [Tomorrow]-[Today] = 1, not 2.
When a worksheet cell is formatted as General Excel will automatically change that format to whatever Excel thinks you have probably entered. If you enter what Excel recognizes as a date the cell format will be changed to Date and if the way you entered the date was by function, such as =TODAY() the cell will display "6/3/2021" using the date format specified in your Windows International settings.
But if you manually change the cell format back to General or Number the display will change to 44262. That's the way you can test if your cell contains a "true" date, with which you can do calculations, or a "fake" date, which is just a text string which is nice to look at but otherwise useless.
Related
I have the results of a survey with birthdays in various date formattings.
01.01.1990
02/03
04.05 etc.
Every time Excel sees a day and a month without a year it implies the current year and puts it in the cell without any hesitation. So, when we try to extract a year, we get not the error we expected but the current year, which is nonsense.
How can we avoid this behaviour?
The desireable result is:
One column with one formula
If the year is written, we extract it using =YEAR()
If it is absent, we just do anything else, for instanse put "".
Basic change of formatting doesn't change the implication of the current year. And if we change the format of the whole column from date to text, we cannot use the formula "YEAR" anymore to any of the cells.
This is a task for students who can deal with Excel and Google Sheets only, Python is not an option.
I would be very grateful for any help!
Both Excel and Google Sheets stores date as a number (day count) starting from 1900/01/01 so it either assumes year for you or doesn't recognize it as date at all.
If you convert date to number, 1900/01/01 will be 1, 2023/01/16 will be 44942 (as it is 44942 day counting from 1900/01/01).
I assume that survey can't be filled by people born this year so just "filter" them out:
If date is in A1 use formula:
=IF(OR(YEAR(A1)=2023,YEAR(A1)=1900),"",YEAR(A1))
This will print nothing if captured year is 2023 or 1900 (this behavior also possible when dealing with dates without years).
I have daily data from 01-Jan-2005 till 29-Dec-2017. I want for each year to select the last day of March, June, September, and December, alongside their respective data. Part of the data:
Date Variable
30-Mar-2005 1.2943
31-Mar-2005 1.2964
1-Apr-2005 1.2959
4-Apr-2005 1.2883
5-Apr-2005 1.281
I.E: For 2005, I want the dates of 31-March-2005, 30-June-2005, 30-September-2005, and 30-Dec-2005. Desired output:
Date Variable
31-Mar-2005 1.2964
30-Jun-2005 1.9859
30-Sep-2005 1.2233
30-Dec-2005 1.2814
I currently have the build in excel formulas (i haven't installed any other plug-ins etc).
More specifically: on the left i have the data, and on the right the desired output.
Not sure if this is going to work to you, but anyways.
Looks like you always look at the last day of months March, June, September and December on a specific year (in example, 2005).
But you are not looking for the last natural day of each month. You want the last day of each month that appears in your data (in example, that explains why you use 30 december 2005 instead of 31, because there is no 31).
In Excel, dates are numbers. The more you go in the future, a bigger number is related. Knowing this, you can get the date for each month just looking the MAX value of a range of dates.
But first, you need to define the range of dates, using 2 conditions:
Month of date must be March, June, September and December
You want dates for a specific year (in example, 2005).
To get this, you need an array formula. My formula gets the max day of a specific month and year. To test it, in my Excel I did a dates series, starting in 01/01/2005 and done in 31/12/2017. I deleted manually 31/12/2005 because that date has no data.
In cell I4, just type the year you want to check. The formula will get he last day of months March, June, September and December of that year.
My array formula is:
=MAX(IF(MONTH(IF(YEAR($A$4:$A$4750)=$I$4;$A$4:$A$4750))=3;$A$4:$A$4750))
IMPORTANT!: Because it is an array formula, you will need to type it
as usual, and then, instead of pressing Enter press
CTRL+SHIFT+ENTER
You need 4 times this formula. Just change the 3 (March) for the number of the month you need (6,9 and 12).
Now that you have the dates, you just need a VlookUp to get the value you want.
=VLOOKUP(G5;$A$4:$B$4750;2;false)
If I change the year value, i get those new values:
If you want to check the file. I uploaded an example to Gdrive, so you can download if you want.Download
Anyways, try to adapt this formulas to your needs.
I converted a list of Euro conversions into a Table and used structured references. But you can use normal range references if you prefer.
In some other table, enter the following formula, where $A$45 refers to the first quarter ending date in your data table.
F2: =IF(EOMONTH($A$45,(ROWS($1:1)-1)*3)>MAX(Table1[Date]),"",LOOKUP(2,1/(EOMONTH($A$45,(ROWS($1:1)-1)*3)>=Table1[Date]),Table1[Date]))
In the adjacent column, enter the formula:
G2: =IFERROR(VLOOKUP(F3,Table1,2,FALSE),"")
And fill down until you get blanks.
(in my sample table, the last date is 1/27/2006 so the last included "End date" is 12/30/2005, there being no data for 12/31/2005)
So, there are two cases
When you have the exact last days of the month. (Its simpler).
I had a fortnightly data. I adopted this simple and innovative method. From all the dates, I first extracted the day using Day() function. for example, Day(A1). (Remember, while doing this, do not delete your original date column. Do it in a separate column as this would help you match the dates later).
Then I sorted the data using the Day column, just constructed before, in decreasing order. This would place all end dates at first. And then deleted the starting dates which were at bottom. So, now I am left with only end dates but obviously months are not in order.
So, create another column extracting just the month and year from the original date column using =MONTH(A1) & "/" & YEAR(A1). Sort the data using this column. And, you are good to go!
When you do not have the exact last days, but maximum dates like the one shown above in picture.
In this, while deleting the initial dates, you would have to take care of which date on-wards you need to delete.
For example, I deleted day 17 on-wards of months with 31 days (including day 17) and day 16 on-wards of months with 30 days (if present) because if there was this date, suppose, 18 April 2018, then this would be the last day of the month as I had a fortnightly data.
I am trying to convert the Day column to a standard date format. 1 for Nov 1 (current month), 2 for Nov 2, and so on. Would be nice if the formula will display the current month. The format for the Day column is in general.
Alternately, use =A2+43039 and format cells as Custom: d-mmm
Also possible to use =A2+"10/31/2017" to make it clearer what you're doing in the formula.
However, if you want it to update with whatever the current month and year is, Ralph's answer is probably best.
Copy the following formula into cell B2 (if that's your Date column and Day is in the A column) and then copy it down:
=DATE(YEAR(TODAY()),MONTH(TODAY()),A2)
I am creating a Table in excel to help determine what the Bi-annual dates would be from an input date.
Example: If the start date of an agreement is 9/1/2017 and Ends 8/31/2018, the Bi-annual dates would be 2/28/18 and 8/31/2018. Dates of service would be 2 months before the end of the agreement period, and six months before the second service date (so 6/30/2018 and 12/31/2017 respectively).
Formula for this:
=IF(ISBLANK(O3), "",IF(EOMONTH(A1, 0)=EOMONTH(O3, -2), "BIANNUAL", IF(EOMONTH(A1, 0)=EOMONTH(O3, -8), "BIANNUAL", "")))
Where A1 refers to January, B1 would be February, and so on thru to December (L1). O3 is the Agreement End Date box, and will be static on the sheet. This formula work perfect for me.
What I am trying to get is a formula for the cells at the top that list the months (Jan-Dec). I need a formula that will put the date as 1/31/2018 for Jan, 2/28/2018 for Feb, 9/30/2017 for September (for the current year since September has not passed). The actual day needs to be the last day of the month, and if that month has passed, then the year should be for next year. I have been playing with the DATE function, but cannot get it nailed down.
What I have so far - January 2018:
=DATE(YEAR(TODAY()+365), MONTH(42766), DAY(EOMONTH(42766, 0)))
This works, but not each month will be in 2018. I need the year to change only after the month has passed.
I feel like I'm either over complicating things, or I need a way more complex formula. Please help.
In A1 place the following formula and copy right to L1 or as far as you need to go
=EOMONTH($O$2,COLUMN(A1)-1)
It will display the end of month dates starting with the starting month of the contract and increasing by 1 month for each column you move right.
In the image below, it is the same formula in row 1 and row 2. Row one I choose custom format instead of date and set the custom format to mmmm. 4 m's will give you the full month, and 3 m's will give you the 3 starting letters of the month.
I actually figured this out this morning just playing with the IF function. My goal was to have the sheet update itself without having to change the dates every time your open it. So that the file could be shared with others and all you would have to enter is the end of the contract date, and it will list out Biannual, Tri-annual, and Quarterly months (see image).
Formula:
=IF(DATE(YEAR(TODAY()), MONTH(42766), DAY(EOMONTH(42766, 0)))<TODAY(), DATE(YEAR(TODAY()+365), MONTH(42766), DAY(EOMONTH(42766, 0))), DATE(YEAR(TODAY()), MONTH(42766), DAY(EOMONTH(42766, 0))))
Where I used the serial for each month (in this case 1/31/2017, as I didn't need to worry about the year)
Results
This question is for educational purposes only, as I have already solved this problem in a way I dislike...
Sheet looks following and has rows for months, in each row there is a column for days that month and for current month
I have a formula that calculates how many days have passed this month or month that has passed which is used in some later calculations.
=TODAY()-DATE(2017,6,1)+1
Currently at the end of month I have to go and change formula to (as they go over 31 day in a month)
=DATE(2017,5,31)-DATE(2017,5,1)+1
What I would like to do is something like:
=MIN(TODAY(),DATE(2017,6,30))-DATE(2017,6,1)+1 to take whichever date is less, so I could do the formulas for the months in advance and not need to go back to it at the end of every month...
I can do it like =MIN(TODAY()-DATE(2017,6,1),DATE(2017,6,30)-DATE(2017,6,1))+1 but it looks somewhat not nice...
How do I compare two dates and take one that is smaller?
After a chat room discussion, it appears that one problem was the formatting of the results.
So =MIN(TODAY(),DATE(2017,6,30))-DATE(2017,6,1)+1 is sufficient
Excel stores dates as serial numbers with 1 = 1-Jan-1900.
If one wants to return a date, the cell containing the formula should be formatted as a date.
If one wants to return a numeric value, the cell containing the formula should be formatted as General or as a number with the appropriate number of decimals.
Excel does not always format the cell as desired by the user, so this may need to be edited.
Days passed for that month is nothing but the day. You can directly use the below formula, I believe.
=min(day(date(2017,6,30)), day(DATE(2017,6,4)))
if you want that as a date. Then you can include another date function to include month and year. If you just want the smaller date itself, then you can directly use the date itself in the min function
=min(date(2017,6,30), date(2017,6,4))
You have TODAY() function to get today date, you can get this month by MONTH function in excel.
TODAY() - DATE(2017, MONTH(TODAY()), 1) + 1
reference
If you want to know how many days have passed, can't you just use
=TODAY()-(EOMONTH(TODAY(),-1)+1)