How do I set a formula or VBA to get around this?
If Date Listed in Column A + (7 Days) Exceed 5th of Upcoming Month then Do Something.
Its like 5th of Each Month is Deadline.
If Column A = 30th March 2015 +(7days)left = 6th April 2015 then Column B = "HolyCrap" Else "You're Safe"
I would really appreciate some help on this.
Let's try this formula:
=IF(AND(DAY(A1+7)>5,DAY(A1+7)<13),"screwed","safe")
The date in A1 could be in either Date or Number format. You would get the correct Number format after pressing Ctrl+;.
Please test it and let me know if for some date it does not return the correct result.
You can use 3 different functions to achieve this in Excel: IF, TODAY and DAY360.
You need a column to calculate the present date. Use TODAY function for that.
You need a column to calculate the number of days difference between the two dates (that is, the present date and your target date). Use the DAYS360 function for that.
Then on the cell / Column you require to display whatever you want it to display use the IF function. It will help determine if the current date is over or under your specified value in days, and return whatever value you want displayed; overdue, expired, Yes, No etc. Example:
=IF(P2>30,"Expired","Active")
Related
I have a cell G4 with date and time in a format (Text string):
1/29/2020 1:34:24 PM
I need to convert it to DATE formatted cell. How to do that?
I have tried to get numbers and convert them to DATE with this formula:
=DATE((MID(G4;SEARCH("/";G4)+4;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)+2));(MID(G4;SEARCH("/";G4)+1;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)-1));(LEFT(G4;FIND("/";G4;1)-1)))
So:
I am extracting year:
=MID(G4;SEARCH("/";G4)+4;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)+2)
Month
=MID(G4;SEARCH("/";G4)+1;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)-1)
Day
=LEFT(G4;FIND("/";G4;1)-1)
I am getting as a result:
1.5.2022
I need it as it is now, but output should be 29.1.2020 in this case. Later I want to get day difference two that way formatted dates. Is it possible to do it with formula without performing any other cell formatting operations?
EDIT:
I got it working, the only problem is:
How to extract number (year) after third "/"? My current formula is not correct:
=MID(G4;SEARCH("/";G4)+4;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)+2)
It does not function correct in this case:
2/5/2020 12:21:05 PM
EDIT:
I did it this way (I also had to minus G2 - F2, to get days difference):
=IFERROR(DAYS(MID(G2;SEARCH("/";G2)+1;SEARCH("/";G2;SEARCH("/";G2)+1)-SEARCH("/";G2)-1)&"."&LEFT(G2;FIND("/";G2;1)-1)&"."&MID(G2;FIND("/";G2;FIND("/";G2)+1)+1;4);MID(F2;SEARCH("/";F2)+1;SEARCH("/";F2;SEARCH("/";F2)+1)-SEARCH("/";F2)-1)&"."&LEFT(F2;FIND("/";F2;1)-1)&"."&MID(F2;FIND("/";F2;FIND("/";F2)+1)+1;4));"")
You probably need to replace an order of day.month.year and "." to "/" if you are using different date setting (region). I have one setup, so this seems to work.
FYI DATES in excel are stored as integers. They represent the number of days since 1900/01/01 with that date being 1. TIME is stored as a decimal representing fractions of a day or 24 hours. 0.5 represents noon. 24:00 is not an officially supported time in excel, but will work with some functions.
The DATE Formula is looking for three arguments representing YEAR, MONTH, DAY in that order.
DATE(Year, Month, Day)
You need to pull the text from your string representing these values. I find it easiest to pull each one individually in its own cell to ensure the part of the formula is working first then copy and past that part into the DATE formula so the whole calculation in the end can be performed in one cell.
YEAR
To get the year use the following formula:
MID(G4,FIND("/",G4,FIND("/",G4)+1)+1,4)
MONTH
To get the month use the following formula:
LEFT(G4,FIND("/",G4)-1)
DAY
To get the day use the following formula:
MID(G4,FIND("/",G4)+1,FIND("/",G4,FIND("/",G4)+1)-FIND("/",G4)
COMBINED FORMULA
Place the above formulas into the date formula as follows:
=DATE(MID(G4,FIND("/",G4,FIND("/",G4)+1)+1,4),LEFT(G4,FIND("/",G4)-1),MID(G4,FIND("/",G4)+1,FIND("/",G4,FIND("/",G4)+1)-FIND("/",G4)-1))
Note the only cell reference in the formula is G4. The results of the formula are not in an Excel Date format. Change the formatting of your cell to meet your needs. In your case I would apply a custom cell format of d.m.yyyy
If you have TEXTJOIN,
=TEXTJOIN("/",TRUE,INDEX(FILTERXML("<a>,<b>"&SUBSTITUTE(SUBSTITUTE(TEXT(A1,"dd/mm/yyyy hh:mm:ss"),"/","</b><b>")," ","</b>",1)&"</a>","//b"),N(IF({1},{2,1,3}))))
Depending on your version it may need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.
the reason the second did not work is that Excel actually changed it to a date and a date is a double, not text. So there are no / in the data. so we need to force back to the incorrect string.
Those for whom the TEXTJOIN function is not available can use this:
=DATE(FILTERXML("<DATA><A>" & SUBSTITUTE(SUBSTITUTE(A1;"/";"</A><A>");" ";"</A><A>") & "</A></DATA>";"/DATA/A[3]");FILTERXML("<DATA><A>" & SUBSTITUTE(SUBSTITUTE(A1;"/";"</A><A>");" ";"</A><A>") & "</A></DATA>";"/DATA/A[1]");FILTERXML("<DATA><A>" & SUBSTITUTE(SUBSTITUTE(A1;"/";"</A><A>");" ";"</A><A>") & "</A></DATA>";"/DATA/A[2]"))
I have a series of dates and values:
8.12.2018 12
5.2.2019 32
15.7.2019 89
I would like to use something like (SUMIFS(YEAR(A1:A3);2018) but it's not allowed.
I know, I could extract the year in a separate column, but here I want to ask, if it's possible inside the sumifs function?
Although I thought you couldnt, it has proven by #forwardEd, you can alter criteria in such a way to use SUMIFS, however, you could also look into SUMPRODUCT for this exercize:
=SUMPRODUCT(--(YEAR(A1:A3)=2018),B1:B3)
Assuming your dates are valid excel dates and not dates as strings/text then you can use the SUMIFS formula for a year as follows:
=SUMIFS(B1:B3,A1:A3,">="&date(2018,01,01),A1:A3,"<="&date(2018,12,31))
Basically the formula is saying sum all the values in B1:B3 where the date in A1:A3 is greater than or equal to the first day of the year AND less than or equal to the last day of the year. I choose to write the date using the date function as it is easier to recognize than the integer format of the date. If you want to write just the year as a criteria in say cell c2 then replace 2018 in the above formula with c2.
UPDATE
I have not tested it but since the default for a date without time is 00:00:00 it would mean the formula above would cut off December 31 with almost any sort of time associated with it. Therefor the better cut off would be less than January 1st of the following year instead of less than or equal to December 31st. As such you could revise the above formula to:
=SUMIFS(B1:B3,A1:A3,">="&date(2018,01,01),A1:A3,"<"&date(2019,01,01))
or
Where C2 is the year as an integer
=SUMIFS(B1:B3,A1:A3,">="&date(C2,01,01),A1:A3,"<"&date(C2+1,01,01))
Alternative approach (a little bit less elegant solution, but might be more clear to less advanced users):
=SUMIFS(B1:B4,A1:A4,">="&"01/01/2018",A1:A4,"<="&"31/12/2018")
I want to show specific text for whether something is due for any given month in a financial year or overdue if that month has passed. The formula I am using is as below and works fine until I get to January.
I am using the numerals 7-12 in this formula to represent respective month but am unsure how to ensure the number 1 relates to the next year. For that matter I guess my equation below for overdue for December won't work either.
=IF(MONTH(TODAY())=12,"DUE",IF(MONTH(TODAY())<=12,"",IF(MONTH(TODAY())>=12,"Overdue")))
Any help would be appreciated
Instead of the month number, let A1 equal the first of the month in which it's due. (Note the first of the month is what you'll get if you just type in the month and year, eg August 2014)
=IF(TODAY()<A1,"",IF(TODAY()>EOMONTH(A1,0),"Overdue","Due"))
Here is a solution that you can use. This includes a =YEAR( function and an =AND function to extend on what you already have.
The formula you can use is here.
=IF(AND(MONTH(TODAY())=MONTH(A2),YEAR(TODAY())=YEAR(A2)),"Due",IF(AND(MONTH(TODAY())>MONTH(A2),YEAR(TODAY())>=YEAR(A2)),"Overdue",""))
you can add the year into the comparison which will eliminate your problems with January.
Just wrap the month check and year check in an =AND( function when both conditions are TRUE you can enter your result.
I have a date in the format of "4/26/2013". I want to see if that date is prior than the current year, whatever that current year may be (don't want to hardcode 2013) and count how many of the rows match that criteria. Say there are 6 rows of dates in that format:
=COUNTIF(C2:C7, YEAR(Today()))
This threw an error. I'm new to Excel, so I probably made a huge mistake! Can anyone see what is wrong with this?
Thanks!
If C2:C7 contain dates you need to compare them to the 1st of January in the current year, e.g.
=COUNTIF(C2:C7,"<"&DATE(YEAR(TODAY()),1,1))
or you can use SUMPRODUCT like this
=SUMPRODUCT((YEAR(C2:C7)<YEAR(TODAY()))*(C2:C7<>""))
I just figured it out. My syntax was wrong. The answer to the above example was:
=COUNTIF(C2:C7, ">"&YEAR(TODAY()))
That returned the number of dates in C2 - C7 that were prior to the current year.
So I have a cell with 7/6/2012 10:26:42 inputted, I want to show the date difference from today in another cell.
I tried to extract 7/6/2012 with =LEFT(A1, Find(" ", A1, 1) -1) but turned out theres a value error.
The formula works when I make A1 '7/6/2012 10:26:42, however it is not ideal because I have to work with the whole column.
You can use the datedif function to find out difference in days.
=DATEDIF(A1,TODAY(),"d")
Quote from excel.datedif.com
The mysterious datedif function in Microsoft Excel
The Datedif function is used to calculate interval between two dates in days, months or years.
This function is available in all versions of Excel but is not documented. It is not even listed in the "Insert Function" dialog box.
Hence it must be typed manually in the formula box.
Syntax
DATEDIF( start_date, end_date, interval_unit )
start_date from date
end_date to date (must be after start_date)
interval_unit Unit to be used for output interval
Values for interval_unit
interval_unit Description
D Number of days
M Number of complete months
Y Number of complete years
YD Number of days excluding years
MD Number of days excluding months and years
YM Number of months excluding years
Errors
Error Description
#NUM! The end_date is later than (greater than) the start_date
or interval_unit has an invalid value.
#VALUE! end_date or start_date is invalid.
If that's a valid date/time entry then excel simply stores it as a number (days are integers and the time is the decimal part) so you can do a simple subtraction.
I'm not sure if 7/6 is 7th June or 6th July, assuming the latter then it's a future date so you can get the difference in days with
=INT(A1-TODAY())
Make sure you format result cell as general or number (not date)
For the difference between A1 and Today's date you could enter:
=ABS(TODAY()-A1)
which returns the (fractional) number of days between the dates.
You're likely getting a #VALUE! error in your formula because Excel treats dates as numbers.
DAYS(start_date,end_date):
For example:
DAYS(A1,TODAY())
Why don't you just make it easy and simple. If I need to know the number of days between today and say, March 10th, 2015, I can just enter the simple formula.
Lets say the static date is March 10th, 2015, and is in cell O5.
The formula to determine the number of days between today and O5 would be, =O5-Today()
Nothing fancy or DATEDIF stuff. Obviously, the cell where you type this formula in must have a data type of 'number'. Just type your date in normally in the reference cell, in this case O5.
=ROUND((TODAY()-A1)/365,0) will provide number of years between date in cell A1 and today's date
*In all instances the # refers to the cell number
You really don't need the datedif functions; for example:
I'm working on a spreadsheet that tracks benefit eligibility for employees.
I have their hire dates in the "A" column and in column B is =(TODAY()-A#)
And you just format the cell to display a general number instead of date.
It also works very easily the other way: I also converted that number into showing when the actual date is that they get their benefits instead of how many days are left, and that is simply
=(90-B#)+TODAY()
Just make sure you're formatting cells as general numbers or dates accordingly.
Hope this helps.