Hi B4X Dev's,
I make this code for get working days in month, you can get all days, days without saturday or days without saturday and sunday.
You can make it more simple if you can:
For run it its very simple:
I make this code for get working days in month, you can get all days, days without saturday or days without saturday and sunday.
You can make it more simple if you can:
B4X:
Sub Process_Globals
Type Avalibles_Days(Monday As Boolean, Tuesday As Boolean, _
Wednesday As Boolean,Thursday As Boolean,Friday As Boolean, _
Saturday As Boolean,Sunday As Boolean)
End Sub
B4X:
Public Sub laborableDays(Month As Int, Year As Int, Mode As Int) As Int
Dim days_count As Int = DateUtils.NumberOfDaysInMonth(Month,Year)
Dim AD As Avalibles_Days
AD.Initialize
Select Mode
Case 1 'DAYS WITHOUT SATURDAY AND SUNDAY
AD.Monday = True
AD.Tuesday = True
AD.Wednesday = True
AD.Thursday = True
AD.Friday = True
AD.Saturday = True
AD.Sunday = False
Case 2 'DAYS WITHOUT SUNDAY
AD.Monday =True
AD.Tuesday =True
AD.Wednesday =True
AD.Thursday =True
AD.Friday =True
AD.Saturday =False
AD.Sunday =False
Case Else 'ALL DAYS
AD.Monday =True
AD.Tuesday =True
AD.Wednesday =True
AD.Thursday =True
AD.Friday =True
AD.Saturday =True
AD.Sunday =True
End Select
Dim days_result As Int = 0
For i = 1 To days_count
Dim day As String = i & "/" & Month & "/" & Year
Dim l As Long = DateTime.DateParse(day)
day = DateUtils.GetDayOfWeekName(l)
'My language is spanish that's the reason the days are in spanish, but you can change it for your language:
If day = "lunes" And AD.Monday = True Then days_result = days_result + 1
If day = "martes" And AD.Tuesday = True Then days_result = days_result + 1
If day = "miércoles" And AD.Wednesday = True Then days_result = days_result + 1
If day = "jueves" And AD.Thursday = True Then days_result = days_result + 1
If day = "viernes" And AD.Friday = True Then days_result = days_result + 1
If day = "sábado" And AD.Saturday = True Then days_result = days_result + 1
If day = "domingo" And AD.Sunday = True Then days_result = days_result + 1
Next
Return days_result
End Sub
For run it its very simple:
B4X:
laborableDays(Month As Int, Year As Int, Mode As Int)
'Mode 0 = All Days
'Mode 1 = Days With out Sunday
'Mode 2 = Days With out Saturday and Sunday
Log("Laborable days :" & laborableDays(12, 2020, 0))
'Return 31
Log("Laborable days :" & laborableDays(12, 2020, 1))
'Return 27
Log("Laborable days :" & laborableDays(12, 2020, 2))
'Return 23
Last edited: