Android Question verify the correctness of the date

DonManfred

Expert
Licensed User
Longtime User
Something like

B4X:
Sub ValidDate(ChkDate As String) As Boolean
    Dim old As String = DateTime.DeviceDefaultDateFormat
    DateTime.DateFormat = "dd.MM.yyyy" ' Please adapt to your needs!
    Dim dcf As Int = 0
    Dim GoodDate As String
    Try
        GoodDate = DateTime.DateParse(ChkDate)
    Catch
        GoodDate = ""
        dcf = 1
    End Try
    DateTime.DateFormat = old
    If dcf = 0 Then
        Return True
    Else
        Return False
    End If
End Sub

To use it like this:
B4X:
    Log($"Valid Date: 19.03.2018 -> ${ValidDate("19.03.2018")} "$)
 
Upvote 0

Gianluca Esposito

Member
Licensed User
Longtime User
hi, If the date set is 31/02/2018, the AnotherDataPicket returns 3/02/2108 and then the date is correct :(

B4X:
Private dpDataRiconsegna As AnotherDatePicker

DataPresuntaConsegna=DateTime.Date(dpDataRiconsegna.Date)
    
If ValidDate(DataPresuntaConsegna) Then
 
Upvote 0
Top