Jump to content
  • 0

Berekenen van reeks datums


Bruno VDK

Question

Posted

Ik heb (naar alle waarschijnlijkheid) een custom function nodig dat het volgende weergeeft:

 

als reeks van datums, iedere dag tussen dateStart en dateEnd die valt op de 15de van de maand en de laatste dag van die maand.

 

Voorbeeld:

 

dateStart: 01-02-2014

dateEnd: 08-04-2014

 

List returned:

15-02-2014

28-02-2014

15-03-2014

31-03-2014

 

Heeft iemand iets op het schap liggen ?

3 answers to this question

Recommended Posts

  • 0
Posted

Zoiets?

 

Functie:

DatumReeks ( theStart ; theEnd )

 

Code:

Let (
[
xStart = Max ( Date ( Month ( theStart ) ; 15 ; Year ( theStart ) ) ; theStart ) ;
xNext = If ( Day ( xStart ) = 15 ; xStart ; Date ( Month ( xStart ) + 1 ; 0 ; Year ( xStart ) ) ) 
]  ;

If ( xNext ≤ theEnd ; xNext ; "" ) & "¶" & If ( xNext > theEnd ; "" ; DatumReeks ( xNext + 1 ; theEnd ) )

)

 

rmw

  • 0
Posted

Werkt perfect, rmw, bedankt.

 

Kan dit aangepast worden met enkele aanvullende eisen?

 

Indien een gegeven veld de waarde "weekly" heeft, moeten we de dichtsbijzijnde zaterdag hebben.

Indien een gegeven veld de waarde "bi-weekly" heeft moeten we de 15 van de gegeven maand hebben, en als het al voorbij de 15de is moeten we de laatste dag van de gegeven maand hebben.

 

Alles te berekenen vanaf dateStart.

  • 0
Posted

Er vanuit gaande dat bij een wekelijkse reeks het einde van de maand niet meer van toepassing is, kan dat als volgt:

 

Functie:

DatumReeks ( theStart ; theEnd ; theFrequency )

Code:

Let (
[
xCheck = If ( theFrequency = "weekly" ; Day ( theStart + ( 7 - DayOfWeek ( theStart ) ) ) ; 15 ) ;
xStart = If ( theFrequency = "weekly" ; theStart + ( 7 - DayOfWeek ( theStart ) ) ; Max ( Date ( Month ( theStart ) ; xCheck ; Year ( theStart ) ) ; theStart ) ) ;
xNext = If ( Day ( xStart ) = xCheck ; xStart ; If ( theFrequency = "weekly" ; xStart + 7 ; Date ( Month ( xStart ) + 1 ; 0 ; Year ( xStart ) ) ) ) 
]  ;

If ( xNext ≤ theEnd ; xNext ; "" ) & "¶" & If ( xNext > theEnd ; "" ; DatumReeks ( xNext + 1 ; theEnd ; theFrequency ) )

)

Zoals je ziet wordt alleen op frequentie "weekly" gecontroleerd. Elke andere inhoud wordt per definitie als "bi-weekly" behandeld.

 

rmw

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...