Weeknummers op verschillende manieren

Met dank aan Mehmet Okul vooor zijn post op onze Visual Objects Nieuwsgroep en de originele auteurs die hun bijdragen leverden op comp.lang.clipper.visual-objects.


FUNCTION Week( _dDatum AS DATE ) AS DWORD PASCAL

   LOCAL _nWoche   AS DWORD
   LOCAL _dJahrAnfang AS DATE
 LOCAL _dTemp    AS DATE

 _dTemp := _dDatum + 8
   _dJahrAnfang := KwBeginn( Year( _dTemp ) )
 IF _dJahrAnfang > _dDatum // dDatum gehört noch zur letzten Woche des
Vorjahrs
    _dJahrAnfang := KwBeginn( Year( _dTemp ) - 1 )
 ENDIF
   _nWoche      := Integer( ( _dDatum - _dJahrAnfang ) / 7 ) + 1

RETURN _nWoche

STATIC FUNCTION KwBeginn( _nJahr AS DWORD ) AS DATE PASCAL
 // Liefert den Montag der ersten Woche des Jahres

   LOCAL _dJahrAnfang AS DATE
   LOCAL _nErstTag    AS DWORD

   _dJahrAnfang := ConDate( _nJahr, 1, 1 )
   _nErstTag    := TdW( _dJahrAnfang )
   _dJahrAnfang := _dJahrAnfang + 8 - _nErstTag
   // Hinweis von Dieter Crispien 100016,1673
   IF _nErstTag < 4 .OR. ( _nErstTag = 4 .AND. ConDate( _nJahr, 2, 29 ) =
NULL_DATE )
      // 1.1. vor Donnerstag oder Schaltjahr + 1.1. ein Donnerstag
      _dJahrAnfang -=  7
   ENDIF

RETURN _dJahrAnfang

=========
If you haven't already got what you want. Here's 2 other functions, one to
find the week and another to find the first day. You may have to modify them
a little bit, because they are made for Sweden, but a least you get the
idea.

Week of Date

FUNC GMF_WoD(dDay AS DATE) AS WORD STRICT
 LOCA wRetVal AS WORD
 LOCA lOldCent AS LOGIC
 LOCA dStart AS DATE
 LOCA w1,wDays,wInitDays AS WORD
 LOCA iDays AS LONGINT

 lOldCent := SetCentury(TRUE)

 dStart :=CToD(NTrim(Year(dDay))+".01.01")

 FOR w1 := 1 UPTO 7
  IF DoW(dStart+wInitDays) = 2
   EXIT
  ENDI
  ++wInitDays
 NEXT w1

 iDays := (dDay-dStart+1)-wInitDays

 wDays := Max(iDays,1)

 wRetVal := Ceil(FLOAT(wDays)/7)

 IIF(wInitDays>3 .AND. iDays>0,++wRetVal,NIL)

 SetCentury(lOldCent)

RETU wRetVal

First day of Week

FUNC GMF_1DoW(wYear AS WORD, wWeek AS WORD) AS DATE STRICT
 LOCA dRetVal,dOne AS DATE
 LOCA bDay AS BYTE
 LOCA aDay AS ARRAY
 LOCA lOldCent AS LOGIC

 lOldCent := SetCentury(TRUE)

  dOne := CToD(NTrim(wYear)+".01.01") // AppWin_BookMark: Last day of las
year!

  aDay := {01,00,06,05,04,03,02}

  bDay := aDay[DoW(dOne)]

  --wWeek

  dRetVal := dOne + (wWeek * 7 + bDay)

  IIF(bDay>3, dRetVal:=dRetVal-7 , NIL)

  dRetVal := dRetVal

 SetCentury(lOldCent)

RETU dRetVal

Commentaar van anderen:
ChristianLouboutin op 14-8-2010 om 11:27
Christian Louboutin Shoes, Christian Louboutin, Christian Louboutin Shoes, Wedding Shoes, Christian Louboutin Copyright 2010, Chemicals Chemistry via VerticalNews. Christian Louboutin Shoes, Wedding Shoes Pattinson great actorly virtue is that he wears clothes well, so it too bad he slackered-out in cargo pants here. Christian Louboutin, Christian Louboutin Shoes, Wedding Shoes, Discount Christian Louboutin, Manolo Blahnik Shoes Tyler is less revealed than telegraphed through accessories a dead brother depth, a pack-a-day habit angst, a bookstore job smart, Discount Christian Louboutin, Louboutin, Christian Louboutin Sale, Louboutin Shoes, Sale Christian Louboutin Rodita zip sandals New style Black 14 a rich, aloof, and permanently disappointed daddy Pierce Brosnan. Louboutin Sale, Herve Leger Bandage Dress, Herve Leger Dress, Herve Leger V Neck Dress, Herve Leger Bandage Dress Falling for You Love, angst, and something else is in the air in Remember Me Remember Me Herve Leger Dress, Chanel Shoes, Yves Saint Laurent Shoes, Manolo Blahnik Shoes Platform Cage Sandal 13 by Allen Coulter Summit Entertainment Opens March 12 Putatively a new romance starring Robert Pattinson, Remember Me begins like a vigilante movie Alexander Wang Shoes, Louboutin Shoes, Louboutin Sale, Louboutin, Christian Louboutin Sale, Buy Christian Louboutin A Brooklyn subway platform, a racially charged stickup girl watches her mother get shot. Christian, Christian Louboutin Discount, Christian Dior Shoes, Christian Louboutin Pumps Pattinson great actorly virtue is that he wears clothes well, so it too bad he slackered-out in cargo pants here.
Geef feedback:

CAPTCHA image
Vul de bovenstaande code hieronder in
Verzend Commentaar