Question:
Excel date formarting?
sley
2008-05-14 06:07:47 UTC
I have a number which is a date in this formart Day week year. the number is 6427 so thats day 6 of week 42 year 2007. is there a way i could change this to date/month/year Thanx
Four answers:
AnalProgrammer
2008-05-14 06:33:04 UTC
Assuming your number is in cell A1

Place this formula in B1 and remove the spaces



=MID(A1 ,2 ,LEN(A1) - 2) *7 + DATE(RIGHT(A1 ,1)+100 ,1 ,LEFT(A1 ,1))



now format the cell B1 as Date

If the day number is wrong then you may have to add or subtract 1 from LEFT(A1 ,1)
JA12
2008-05-14 06:27:57 UTC
There isn't a standard function to deal with DWY, but here's a bit of VBA that will do the job. It expects a 3 to 5 character string.



Put your DWY as a string 'dw[w]y[y]' in A1



A1 ='117' -- 2007

B1 =ConvertDWY(A1)

the second parameter is the length of the year section so if the year is more than 1 character

A1 ='1110' -- 2010

B1 =ConvertDWY(A1,2)



-------------------------------------

Function ConvertDWY(ByVal varIn As String, Optional ByVal YearLen As Long = 1) As Date



Dim d, dd As Long

Dim m As Long

Dim w, ww As Long

Dim y As Long

Dim days As Long

Dim adddays As Long

Dim week As Long

Dim sDate As String

Dim SoY As Date



d = Left(varIn, 1)

y = 2000 + CLng(Right(varIn, YearLen))

w = Mid(varIn, 2, Len(varIn) - Len(d) - YearLen)



' get the whole number of days for the week value

week = (w - 1) * 7

sDate = "01/01/" & CStr(y)

' get the day 01/01 falls on

ww = (DatePart("w", sDate, vbSunday, vbFirstFullWeek) - 1) * -1

' get the first date of the year

SoY = DateAdd("d", ww, sDate)

' get the total number of days

days = week + d

' add the total number of days to the start date

ConvertDWY = DateAdd("d", (days + ww), SoY)



End Function

-------------------------------------

The function returns a serial date so format B1 to a Date.



Edit: This is now working with the correct first day of the year.
Sam
2008-05-14 06:14:59 UTC
right click on mentioned cell and choose format cell then go to date category and choose the format that you want!



Good luck
Sarah M
2008-05-14 11:31:51 UTC
Use can use DATE (year, month, day). Leave month blank, and it'll count up on it's own.



=DATE("200"&RIGHT(G3,1), ,LEFT(G3,1) + (MID(G3,2,2)-1)*7)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...