Discussion:
ISOweekNumber
(too old to reply)
Evertjan.
2018-03-23 13:00:30 UTC
Permalink
ISOweekNumber = DatePart("ww", theDate, vbMonday, vbFirstFourDays)

That took me a week.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Auric__
2018-03-23 16:55:02 UTC
Permalink
Post by Evertjan.
ISOweekNumber = DatePart("ww", theDate, vbMonday, vbFirstFourDays)
That took me a week.
Neat. Into ye olde book of tricks it goes.
--
Nothing lasts... correction: nothing good lasts.
Evertjan.
2018-03-24 12:11:26 UTC
Permalink
Post by Auric__
Post by Evertjan.
ISOweekNumber = DatePart("ww", theDate, vbMonday, vbFirstFourDays)
That took me a week.
Neat. Into ye olde book of tricks it goes.
Well, the reverce is not that simple,
the best I can do is this:

function ISOweekNumber(theDate)
ISOweekNumber = DatePart("ww", theDate, vbMonday, vbFirstFourDays)
end function

function dateFromISOweekNumber( theYear, IsoWkNr, Wkday ) ''' monday = 1
firstDayY = dateserial(theYear, 1, 1)
WeekNumberFirstDayY = ISOweekNumber(firstDayY)
WeekDayFirstDayY = weekday(firstDayY, vbMonday)
if WeekNumberFirstDayY <> 1 then firstDayY = firstDayY + 7
dateFromISOweekNumber = firstDayY - (WeekDayFirstDayY - 1) +
( 7 * (IsoWkNr -1 ) + (Wkday - 1))
end function

Anyone with a better/shorter, or more correct solution?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Auric__
2018-03-24 16:11:31 UTC
Permalink
Post by Evertjan.
Post by Auric__
Post by Evertjan.
ISOweekNumber = DatePart("ww", theDate, vbMonday, vbFirstFourDays)
That took me a week.
Neat. Into ye olde book of tricks it goes.
Well, the reverce is not that simple,
function ISOweekNumber(theDate)
ISOweekNumber = DatePart("ww", theDate, vbMonday, vbFirstFourDays)
end function
function dateFromISOweekNumber( theYear, IsoWkNr, Wkday ) ''' monday = 1
firstDayY = dateserial(theYear, 1, 1)
WeekNumberFirstDayY = ISOweekNumber(firstDayY)
WeekDayFirstDayY = weekday(firstDayY, vbMonday)
if WeekNumberFirstDayY <> 1 then firstDayY = firstDayY + 7
dateFromISOweekNumber = firstDayY - (WeekDayFirstDayY - 1) +
( 7 * (IsoWkNr -1 ) + (Wkday - 1))
end function
Anyone with a better/shorter, or more correct solution?
In 30 seconds of looking at the code, I can't think of any way to improve it.
But if it returns the correct date, I'd say it's good.
--
When you are so drunk and obnoxious that we kick you out and you literally
have to be dragged out, and your ejection causes an entire room full of
people to cheer and applaud, you have had TOO MUCH TO DRINK.
Dave "Crash" Dummy
2018-03-23 17:25:16 UTC
Permalink
Post by Evertjan.
ISOweekNumber = DatePart("ww", theDate, vbMonday, vbFirstFourDays)
That took me a week.
Cool. What is ISOweekNumber?
--
Crash

Absence tempts the heart to wander.
Dave "Crash" Dummy
2018-03-23 17:48:41 UTC
Permalink
Post by Dave "Crash" Dummy
Post by Evertjan.
ISOweekNumber = DatePart("ww", theDate, vbMonday, vbFirstFourDays)
That took me a week.
Cool. What is ISOweekNumber?
Never mind. Google is full of information about ISO weeks.
--
Crash

"Politics have no relation to morals."
~ Niccolo Machiavelli ~
Continue reading on narkive:
Loading...