Hi B4X Dev's:
Hi i make another sub for get the day elapsed in the month
How to use the sub:
Hi i make another sub for get the day elapsed in the month
B4X:
Public Sub CurrentLaborableDays(Date As Long, Mode As Int) As Int
Dim days_count As Int = DateTime.GetDayOfMonth(Today)
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 & "/" & DateTime.GetMonth(Date) & "/" & DateTime.GetYear(Date)
'My language is spanish that's the reason the days are in spanish, but you can change it for your language:
Dim l As Long = DateTime.DateParse(day)
day = DateUtils.GetDayOfWeekName(l)
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
How to use the sub:
B4X:
CurrentLaborableDays(Date as Long, Mode as Int) as Int
'Date is the current day
'Example: Let's say the month is December, if you put the "Current day" = 12/8/2020 when you run the function in
'Mode 0 = 8, Mode 1 = 7, Mode 2 = 6
'Mode 0 = All Days
'Mode 1 = Days With out Sunday
'Mode 2 = Days With out Saturday and Sunday
Log("Days: " & CurrentLaborableDays(DateTime.DateParse("12/8/2020"),0))
'Result 8
Log("Days: " & CurrentLaborableDays(DateTime.DateParse("12/8/2020"),1))
'Result 7
Log("Days: " & CurrentLaborableDays(DateTime.DateParse("12/8/2020"),2))
'Result 6