I need to convert an Excel calendar week date into the actual date.
Excel calendar week format = ww.yyyy (e.g. 31.2014);
Expected output = 7/28/2014 (return the Monday of the week)
What formula should I use ?
It's a bit of a pain: there's no direct function. If A1 contains the year, and A2 contains the week number then,
=MAX(DATE(A1,1,1),DATE(A1,1,1)-WEEKDAY(DATE(A1,1,1),2)+(A2-1)*7+1)
will return the date corresponding to the Monday of that week in that year.
To test it, use =WEEKNUM() and =YEAR() on the computed result, along with =TEXT(,"DDD") to prove it's a Monday.
If #Bathsheba's response works for you, you can do everything in cell B1 with the following command
=MAX(DATE(LEFT(B1,FIND(".",B1)),1,1),DATE(LEFT(B1,FIND(".",B1)),1,1)-WEEKDAY(DATE(LEFT(B1,FIND(".",B1)),1,1),2)+(MID(B1,FIND(".",B1)+1,2)-1)*7+1)
This allows you to put YYYY.WW in B1 and it splits it up for you in the calculation.
Related
How can one return the next date of a given weekday (it could be either a number 1-7 or names Sunday-Saturday).
For example, if today, on Friday 16-Oct-2009 I passed in:
Friday, it would return today's date 16-Oct-2009
Saturday returns 17-Oct-2009
Thursday returns 22-Oct-2009
Here is the Spreadsheet
I have tried this formula:
=A12+(C12+ MOD(7-day(A12),7))
I worked out an answer to my own question
Here is the formula
=date(year(A12),month(A12), day(A12) + mod(C12+ 7-WEEKDAY(A12),7))
This worked for me:
=TODAY()+MOD(4 + 7-WEEKDAY(TODAY()),7)
Just replace TODAY() and 4 (weekday#) for your context.
This is the formula you are seeking.
=A12+(7-WEEKDAY(A12)+B12)
A12 holds the start date. B12 holds the ID of the targeted weekday, e.g. 1 for "Sunday".
A11 must hold a true date, as opposed to a text string that looks like a date. If the latter is the case an error will be displayed. The result is always a date. You can format that date as "dddd" to display a day's name or "dddd, dd-mm-yyyy" to display both date and day.
And here are the mechanics of the formula:- A12-WEEKDAY(A12) returns always the previous Saturday, a date that is always in the past. A12+(7-WEEKDAY(A12)) inverts that calculation, returning always the next Saturday. This date is always in the future except when A12 is a Saturday. That's when the result will be = A12.
Having found a stable base, you can just add the day you want to the Saturday you have. Add 1 (for Sunday) and you get a Sunday. Add 7 and you get a Saturday. All these dates will be in the future.
That's all as you want it except that if WEEKDAY(A12) = B12 you want the same date as in A12 which is a week earlier than the one the formula prefers. This is where I went wrong while in haste. My apologies! This is the correct modification of the formula's result, to wit, conditionally deduct 7 from the calculation.
=A12+(7-WEEKDAY(A12)+B12)-IF(WEEKDAY(A12)=B12,7,0)
This command line gives the last work day of the month (True or False). I don't know how to change the commands to get the first work day of each month. If we are assuming the entire column A is the Date. format is mm/dd/year
AND(WEEKDAY(A2,2)<6,MONTH(WORKDAY(A2,1))<>MONTH(A2))
The first day of the month is
date-DAY(date)+1
In your case:
A2-DAY(A2)+1
To check weather A2 is the first day of its month:
A2 = A2-Day(A2)+1
'Simplify equation
Day(A2) = 1
So as a result =(Day(A2)=1) evaluates to True/False
Regarding your formula weather a date is the last day of the month, that can be done by:
=(A2=EOMONTH(A2,0)
I believe this is what you're looking for
=DAY(A2)=1
Is there any option to compare dates with Date format yyyymmddhhmmss with the current date?
Basically one of my external source have this type of date and I have to compare this date with the current date and check difference in between. I have tried to split those date with LEFT,MID,RIGHT functions, so basically, I have two columns - first with date, second with time, but I cannot find any option to subtract current date with date in column, because results are not coming correct.
Sample of date: 20161112203545
after splitting: 2016-11-12 20:05:45.
Any ideas?
Image produced below with formulas is self explanatory.
Your date :20161112203545 in D4
Formula to convert date in E4 :
=DATE(LEFT(D4,4),MID(D4,5,2),MID(D4,7,2))+TIME(MID(D4,9,2),MID(D4,11,2),RIGHT(D4,2))
Today's Date in F4 : =TODAY()
Formula to get date difference in days in G4 : =DATEDIF(F4,E4,"d")
EDIT
The alternative to Excel DATEDIF would be a User defined function (UDF) that internally uses the VBA DATEDIFF function:
This UDF accepts three parameters:
Start_Date: The days from which the period begins.
End_Date: It is the last date of the period that you wish to calculate.
Unit: It specifies the interval by which you want the difference. Here the unit accepts following values.
Value Description
YYYY Year
Q Quarter
M Month
Y Day of year
D Day
Public Function xlDATEDIF(Start_Date As Date, End_Date As Date, Unit As String) As String
xlDATEDIF = DateDiff(Unit, Start_Date, End_Date)
End Function
In this case usage will be, put formula in H4 =xlDATEDIF(F4,E4,"D")
HTH
Taking the date as
20161112203545 after splitting: 2016-11-12 20:05:45
Is going to cause you some issues as Excel assigns date values with a serial number, and it's going to throw that number off. You could use the =today() function and set it up where you have the date entered, say it is in cell A1, then =A1-today() (formatted as a number) should give you the difference in the amount of days.
Microsoft explanation of using Dates in Excel
I'm not sure if this is possible but I thought I would ask to see if any one may have a solution.
Issue:
I have a macro were the user inputs a date as a string (e.g. 021513) in an input box. It is in string format as it's used to open a file (string at the end of the file name).
From this string (e.g. 021513) I need to derive the following in two separate fields:
Week period (e.g. Week: 11th - 15th).
Month (e.g. February).
Any help or thoughts would be greatly appreciated.
Ciaran
You need DateSerial VBA function - it will return the actual Date value from the parts of your string using Mid and other text functions. Having actual date you'll be able to return e.g. month using Month function.
Perhaps string parts conversion to numbers using CInt will be required as well.
You can also do this with Excel formulas:
Assuming your string is cell A1, use the following formulas:
B1 (date): =DATE(right(A1,2)+2000,LEFT(A1,2),MID(A1,3,2))
C1 weekday: =WEEKDAY(B1,2) - this will return 1 for Monday, 2 for Tuesday, etc.
D1 Start of the week: =B1-C1+1
E1 End of the week: =D1+4
F1 Month: =TEXT(B1,"MMMM")
I've got a column full of dates. How can I check that column to find which date is within a month of todays date, and then return it?
If there is no date within a month, just return blank
Lets say my dates are:
01-Jan-12
01-Apr-12
01-Jul-12
01-Oct-12
01-Jan-13
The code im using is below. A:A is the range of the dates above
=MIN(IF(A:A>TODAY(),A:A))
The issue im having is that if I use the above, it returns 01/01/12 and not 01/01/13. Also, if I change the dates so the next date is December 1st 2012, it still returns 01/01/12
So you really just want the earliest date if that's within a month? If so perhaps try
=IF(MIN(A:A)-TODAY()<=30,MIN(A:A),"")
Assumes dates in column A
If you have past and future dates try this formula
=IFERROR(SMALL(IF(A2:A100>=TODAY(),IF(A2:A100<=TODAY()+30,A2:A100)),1),"")
confirmed with CTRL+SHIFT+ENTER
or for exactly 1 month (rather than 30 days) try using EDATE, i.e.
=IFERROR(SMALL(IF(A2:A100>=TODAY(),IF(A2:A100<=EDATE(TODAY(),1),A2:A100)),1),"")