fanlinux90
Programmer
Between the dates 11/28/2023 and 12/02/2022 I know how many days there are. DATE(2023, 11, 28) - DATE(2022, 12, 02), how can I calculate how many Fridays, Saturdays, and Sundays there are between those two dates?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Create Cursor amonth (dDate D)
Index On Dow(dDate,6)=1 Tag fri binary
Index On Dow(dDate,7)=1 Tag sat binary
Index On Dow(dDate,1)=1 Tag sun binary
nYear= Year(Date())
nMonth = Month(Date())
For nDay=1 to 31
d = Date(nYear,nMonth,nDay)
If Empty(d)
Exit
Else
Insert into amonth values (d)
Endif
EndFor
clear
? 'days of month:',reccount()
Count for Dow(dDate,6)=1 To nFridays
? nFridays
Count for Dow(dDate,7)=1 To nSaturdays
? nSaturdays
Count for Dow(dDate,1)=1 To nSundays
? nSundays
Chriss said:Like always just taking in some library and using without inspeciting it in any detail you'll only partly profit from using soeone elses work you spare to do yourself. You lose full control and can have wrong epectations of whatever library.
Count for Dow(dDate,6)=1 To nFridays
mmerlin said:there is NO submit button on any Tek-Tips page
Index On Dow(dDate,2)>4 Tag frisatsun binary
Index On suchaday Tag sad binary
mmerlin is located in Washington USA according to his profile.Criss said:For Mmerlin I assume the two hours you need to make just one post are due to Chinese or a similar state's censorship?
Using a VPN might be part of the two hour procedure to get through to tek-tips. Very likely, isn't it?Mike Gagnon said:Washington USA according to his profile.
**********
* This demo code
* - calculates total and sub-total of selected weekdays in any date period
* - INCLUDES ending date
**********
goForm = CREATEOBJECT("frmForm")
goForm.Visible = .T.
goForm.Show()
READ EVENTS
CLOSE ALL
CLEAR ALL
RETURN
**********
DEFINE CLASS frmForm as Form
Caption = "Name and number of selected days"
AutoCenter = .T.
BorderStyle = 2
Width = 570
Height = 300
MinButton = .F.
MaxButton = .F.
Themes = .F.
ShowTips = .T.
DIMENSION laSelection[7], laTotalDays[1]
laTotalDays[1] = 0
ADD OBJECT lblSDate as Label WITH Left = 12, Top = 12, Caption = "Start date"
ADD OBJECT lblEDate as Label WITH Left = 114, Top = 12, Caption = "End date"
ADD OBJECT lblSDays as Label WITH Left = 12, Top = 72, Autosize = .T., Caption = "Click to select day"
ADD OBJECT lblTSDays as Label WITH Left = 216, Top = 72, Autosize = .T., Caption = "Total of selected days: "
ADD OBJECT txtSDate as textbox WITH Top = 36, Left = 12, Width = 90, Value = {}
ADD OBJECT txtEDate as textbox WITH Top = 36, Left = 114 , Width = 90, Value = {}
ADD OBJECT lstList as ListBox WITH ;
Top = 96, ;
Left = 12, ;
Width = 120, ;
Height = ThisForm.Height - 24 - 96, ;
ItemBackColor = RGB(0, 240, 240), ;
Anchor = 7, ;
RowSourceType = 1, ;
RowSource = "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", ;
ColumnCount = 1, ;
ColumnWidths = "54, 0", ;
Multiselect = .T., ;
ToolTipText = " CTRL / SHIFT Click to multi-select ", ;
IncrementalSearch = .T.
PROCEDURE lstList.Click()
FOR lnI = 1 TO This.ListCount
IF This.Selected(lni)
ThisForm.laSelection[lni] = ALLTRIM(This.List(lnI, This.BoundColumn))
ENDIF
ENDFOR
ENDPROC
ADD OBJECT cmdDoit as CommandButton WITH Left = 216, Top = 12, Height = 48, Width = ThisForm.Width - 24 - 216, BackColor = RGB(0, 240, 240), ;
FontBold = .T. , FontSize = 12, Caption = "Calculate", Anchor = 11
PROCEDURE cmdDoit.Click()
LOCAL liWeeks, liRDays, liTDays, lcSDay
liWeeks = 0
liRDays = 0
liTDays = 0
liTDays = ThisForm.txtEDate.Value - ThisForm.txtSDate.Value + 1
IF ThisForm.txtSDate.Value = {} OR ThisForm.txtEDate.Value = {} OR ThisForm.txtEDate.Value <= ThisForm.txtSDate.Value
= MESSAGEBOX("Please fill in the dates correctly", 16, "Choose dates")
ELSE
SET SAFETY OFF
ZAP IN csrSelectedDays
SET SAFETY ON
FOR i = 1 TO ALEN(ThisForm.laSelection)
IF VARTYPE(ThisForm.laSelection[i]) = "C"
INSERT INTO csrSelectedDays VALUES (ThisForm.laSelection[i], 0)
ENDIF
ENDFOR
liWeeks = INT(liTDays / 7)
UPDATE csrSelectedDays SET iDays = liWeeks
liRDays = liTDays - (liWeeks * 7)
FOR i = 0 TO liRDays - 1
lcSDay = CDOW(ThisForm.txtSDate.Value + (liWeeks * 7) + i)
IF ASCAN(ThisForm.laSelection, lcSDay) != 0
UPDATE csrSelectedDays SET iDays = iDays + 1 WHERE cName = lcSDay
ENDIF
ENDFOR
IF RECCOUNT("csrSelectedDays") > 0
SELECT SUM(iDays) FROM csrSelectedDays INTO ARRAY ThisForm.laTotalDays
ThisForm.grdSelectedDays.Visible = .T.
LOCATE
ELSE
WITH ThisForm
.grdSelectedDays.Visible = .F.
.laTotalDays[1] = 0
ENDWITH
= MESSAGEBOX("Please choose at least one day", 64, "Choose days")
ENDIF
FOR i = 1 TO ALEN( ThisForm.laSelection)
ThisForm.laSelection[i] = .F.
Endfor
WITH ThisForm
.lstList.Clear()
.lstList.Requery()
.lblTSDays.Caption = "Total of selected days: " + TRANSFORM(ThisForm.laTotalDays[1])
.Refresh()
ENDWITH
ENDIF
ENDPROC
ADD OBJECT grdSelectedDays AS Grid WITH ;
RecordSource = "csrSelectedDays", ;
ColumnCount = -1 , ;
Left = 138, ;
Top = 96, ;
Width = ThisForm.Width - 24 - 138, ;
Height = ThisForm.Height - 24 - 96, ;
BackColor = RGB(0, 240, 240), ;
DeleteMark = .F. , ;
Enabled = .F. , ;
Anchor = 15, ;
Visible = .F.
PROCEDURE grdSelectedDays.Init
WITH This.Column1
.Width = 78
.Header1.Caption = "Day"
ENDWITH
WITH This.Column2
.Width = 60
.Header1.Caption = "Number"
ENDWITH
ENDPROC
PROCEDURE Load()
CREATE CURSOR csrSelectedDays (cName C(18), iDays I)
ENDPROC
PROCEDURE Destroy()
CLEAR EVENTS
ENDPROC
ENDDEFINE
**********
Mike Lewis said:Regarding your lack of a Submit button, I am mystified by your statement that you have add the button yourself. I can't imagine how you do that. And have you reported this is a bug?