Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
13
Erster Beitrag:
vor 2 Jahren
Letzter Beitrag:
vor 1 Jahr, 11 Monaten
Beteiligte Autoren:
iso, kingdr, Paulo Oliveira, Marc De Swert, Tor-Bjarne, GuenterP, Stefan Bentvelsen, Harry W

WeekNumber 04/01/2016

Startbeitrag von iso am 17.11.2015 10:48

Hello

Can someone please check the weeknumber for the date 04/01/2016

(thats uk date format 4th Jan 2016)

im using WD 18 and it outputs Week 1 but it should be week 2? Just want to check if its a bug i need to report or something to do with my settings?

Thanks

ISO

Antworten:

Info (WeekNumber("20160104")) gives me also 1

von Marc De Swert - am 17.11.2015 11:26
Why week 2?
According to ISO 8601 it's week 1.

https://en.wikipedia.org/wiki/ISO_week_date#First_week
http://www.epochconverter.com/date-and-time/weeknumbers-by-year.php?year=2016

von Paulo Oliveira - am 17.11.2015 11:26
mayby because this is the complete begining of the first week

von Marc De Swert - am 17.11.2015 11:27
Hi ISO,

IMHO week 1 is correct (in the Netherlands, with Monday as the first day of the week).

von Stefan Bentvelsen - am 17.11.2015 11:28
Hello

but if you look at weeknumber 05/01/2015

5 jan 2015 which also the 1st monday of the year

this outputs week 2?

also if you select 02/01/2016 it outputs week 0?

Thanks

ISO

von iso - am 17.11.2015 11:35
Hi,

I had this a long time ago with another date..

So i made a wordaround

PROCEDURE WeekNummer(pd_geldigedatum)
ls_WeekDatum is string=Left(pd_geldigedatum,8)
IF NOT DateValid(ls_WeekDatum) THEN
RESULT 0
END
IF WeekNumber(ls_WeekDatum)=0 THEN
IF WeekNumber(datumplus(ls_WeekDatum,-7))=51 THEN
RESULT 52
ELSE IF WeekNumber(datumplus(ls_WeekDatum,7))=1 THEN
RESULT 53
END
END

IF WeekNumber(ls_WeekDatum) > 52 THEN
IF WeekNumber(datumplus(ls_WeekDatum,7)) 1 THEN
RESULT 1
ELSE
RESULT 53
END
ELSE
RESULT WeekNumber(ls_WeekDatum)
END

von Harry W - am 17.11.2015 11:45
If you don't want to get week 0 use iso8601 in the WeekNumber function.

von Paulo Oliveira - am 17.11.2015 12:33
I browsed this link:

http://2016calendarprintable.com/wp-content/uploads/2015/09/2016-Calendar-by-Week-Number-2.png

and gives 1, so I guess it's correct.

HTH

King

von kingdr - am 17.11.2015 12:49
Hi, this is the code to get the correct WeekNumber using the old French WeekNumber algo from WINDEV since WD 5.5 as a start. I've had months of disputes with our friends until they acknowledged that ISO 8601 is the French & in general the European norm for calculationg week numbers since 1997. It's been introduced as law then. The French algo has been in force since Napoleon I. who introduced week numbers first. And yes, the 4th of January, 2016 is in Week# 1 there's no way out!


MyWeek, MyYear are 4-byte int
MyISOYearAndWeek is string

IF DateValid(MyDate) THEN
// show corrected result of WeekNumber(Function)
SWITCH WeekNumber(MyDate)
CASE 0
// WeekNumber(Function) returns week #0 as a partial week with less than 4 days
// in the beginning of a year. The week# should be propagated from the previous year
MyWeek = WeekNumber(NumToString(Val(Left(MyDate,4)) - 1, "4d")+"1231")
MyYear = Val(Left(MyDate,4))-1
CASE 53
// WeekNumber(Function) erroneously returns week #53 on partial weeks with
// less than 4 days at the end of the year. Result should be week #1
IF DateToDay(Left(MyDate,4)+"1231") < 4 THEN
MyWeek = 1
MyYear = Val(Left(MyDate,4))+1
ELSE
// week #53 is correct because 4 or more days of the week are in that year
MyWeek = 53
MyYear = Val(Left(MyDate,4))
END
OTHER CASE
// Results from WeekNumber(Function) 0 and 53 are generally OK
MyWeek = WeekNumber(MyDate)
MyYear = Val(Left(MyDate,4))
END
MyISOYearAndWeek = NumToString(MyYear,"04d")+"-W"+NumToString(MyWeek,"02d")
END

von GuenterP - am 17.11.2015 16:10
Hello

Thanks for your time people, i will use the 'iso8601' format

I guess 2015 because it has 4 days in the 1st week is counted as week 1 and 2016 only has 3 days so is counted as week 53.

ISO

von iso - am 18.11.2015 15:19
Hi,

Just remember weeknumber can have a second ",iso8601" parameter:


n is int = WeekNumber(EDT_StartDate)
n2 is int = WeekNumber(EDT_StartDate,iso8601)

Cheers
Tor-Bjarne

von Tor-Bjarne - am 10.12.2015 16:36
Wow, that's why wx is the best.
Good Job Tor-Bjarne :rp::spos:

Cheers

King

von kingdr - am 11.12.2015 09:59
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.