Android Question B4XDateTemplate: How to disable all days earlier than current date

toby

Well-Known Member
Licensed User
Longtime User
I want to disable all days earlier than today so that users can only select current day or some day in the future.

For example, current day is March 28, 2022, users can't select a day earlier than today (March 28).

Could someone kindly show me how, please?

TIA
 
Solution
My solution based on the post
B4X:
Sub Button1_Click
    Wait For (GetDate) Complete (Ticks As Long)
    If Ticks > 0 Then
        Log($"Selected date: $Date{Ticks}"$)
    End If
End Sub

Private Sub GetDate() As ResumableSub
    Do While True
        Wait For (dialog.ShowTemplate(DateTemplate, "", "", "Cancel")) Complete (Result As Int)
        Dim zero As Long = 0 'type must be exact
        If Result = xui.DialogResponse_Cancel Then Return zero
        Dim Days As Int = DateUtils.PeriodBetweenInDays(DateTime.Now, DateTemplate.Date).Days
        If Days<0 Then
            DateTemplate.Date = DateTime.Now
            Wait For (dialog.Show("Invalid date", "Ok", "", "")) Complete (Result As Int)
        Else
            Return...

toby

Well-Known Member
Licensed User
Longtime User
When the calendar appears, I want all days earlier than current date, March 28, are disabled so that users can't select any of them. to disable old days.jpg
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
My solution based on the post
B4X:
Sub Button1_Click
    Wait For (GetDate) Complete (Ticks As Long)
    If Ticks > 0 Then
        Log($"Selected date: $Date{Ticks}"$)
    End If
End Sub

Private Sub GetDate() As ResumableSub
    Do While True
        Wait For (dialog.ShowTemplate(DateTemplate, "", "", "Cancel")) Complete (Result As Int)
        Dim zero As Long = 0 'type must be exact
        If Result = xui.DialogResponse_Cancel Then Return zero
        Dim Days As Int = DateUtils.PeriodBetweenInDays(DateTime.Now, DateTemplate.Date).Days
        If Days<0 Then
            DateTemplate.Date = DateTime.Now
            Wait For (dialog.Show("Invalid date", "Ok", "", "")) Complete (Result As Int)
        Else
            Return DateTemplate.Date
        End If
    Loop
    Return 0
End Sub
 
Last edited:
Upvote 0
Solution
Top