Page 1 of 1
Calulating with dates
Posted: Wed Oct 24, 2007 7:54 am
by driessen
Hello,
Does someone have a function which returns the exact date in a month if I ask for the first, the second, the third, the fourth of the last wednesday (but this can be any day of the week) of a month ?
Thanks a lot in advance.
hi
Posted: Wed Oct 24, 2007 2:30 pm
by avista
I AM NOT SURE WHAT EXACTLY YOU NEED BUT I THINK THIS IS IT ...
Ask if you need something to explain ...
Best Regards,
----------------------------------------------------
// Testing
#include "FiveWin.ch"
//------------------------------------------------------------------------//
function Main()
local oDlg
local nYear := 2000
local nMonth := 1
local nOrder := 1
local oDay
local cDay := "Monday"
local aDays := { "Monday", "Tuesday", "Wednesday", "Thursday", ;
"Friday", "Saturday", "Sunday" ;
}
SET DATE GERMAN
SET EPOCH TO 1980
DEFINE DIALOG oDlg TITLE "Date ..." SIZE 300,200 PIXEL
@ 5, 5 SAY "Year:" OF oDlg PIXEL
@ 20, 5 SAY "Month:" OF oDlg PIXEL
@ 35, 5 SAY "Order:" OF oDlg PIXEL
@ 35, 90 SAY "St" OF oDlg PIXEL
@ 50, 5 SAY "Day:" OF oDlg PIXEL
@ 5, 50 GET nYear OF oDlg SIZE 35, 12 PIXEL PICTURE "9999" ;
VALID nYear >= 2000 .and. nYear <= 2999
@ 20, 50 GET nMonth OF oDlg SIZE 35, 12 PIXEL PICTURE "99" ;
VALID nMonth >= 1 .and. nMonth <= 12
@ 35, 50 GET nOrder OF oDlg SIZE 35, 12 PIXEL PICTURE "9" ;
VALID nOrder >= 1 .and. nOrder <= 5
@ 50, 50 COMBOBOX oDay VAR cDay ITEMS aDays OF oDlg SIZE 55,100 PIXEL
@ 65, 5 BUTTON "&Date" OF oDlg SIZE 35,12 ;
ACTION MsgInfo(GetDate(oDlg,nYear,nMonth,nOrder,cDay)) ;
PIXEL
@ 65, 50 BUTTON "&End" OF oDlg SIZE 35,12 ACTION oDlg:End() PIXEL
ACTIVATE DIALOG oDlg CENTERED
return nil
//------------------------------------------------------------------------//
function GetDate(oDlg,nYear,nMonth,nOrder,cDay)
local aDaysInMonth := {}
local dDate := ctod (" ")
local nOrdered := 0
local i := 0
for i = 1 to 31
dDate := ctod( strzero(i,2)+"."+strzero(nMonth,2)+"."+right(strzero(nYear,4),2) )
if day(dDate) > 0
aadd( aDaysInMonth , {dDate, cdow(dDate)} )
endif
next
nOrdered := 0
for i = 1 to len(aDaysInMonth)
if aDaysInMonth[i,2] = cDay
nOrdered := nOrdered + 1
if nOrdered = nOrder
return aDaysInMonth[i,1]
endif
endif
next
return "No requested day !"
so
Posted: Thu Oct 25, 2007 12:13 pm
by avista
So is that or no ?
Ask if need something else ....
Best regards