Android Question datetime, parse and ticks

Pedro Caldeira

Active Member
Licensed User
Longtime User
Hello All,
Need some help with a strange result that I am getting.
I have some from and to dates to enquire the user to input date limits to after compare with some files .Lastmodified attribute.
I am using the date format and code as follows

B4X:
DateTime.DateFormat = "yyyy-MM-dd"
Dim ValFrom As Long = DateTime.DateParse(lblUPLDataDesde.Text)
Dim ValTo As Long = DateTime.DateParse(lblUPLDataAte.Text)

If (fname.ToLowerCase.EndsWith("lurl") Or fname.ToLowerCase.EndsWith("log") Or _
    fname.ToLowerCase.EndsWith("svrlog") Or fname.ToLowerCase.EndsWith("json") Or _
    fname.ToLowerCase.EndsWith("set")) Then
    Dim FileDate As Long = File.LastModified(Starter.SharedFolder, fname)
    Log($"LOG FileDate: $date{FileDate}"$)
    Log($"LOG ValFrom: $date{ValFrom}"$)
    Log($"LOG ValTo: $date{ValTo}"$)
    If FileDate >= ValFrom And FileDate <= ValTo Then
      ListFilesLOGS.Add(fname)
     End If
 End If

But it cannot include the files because even the dates are all 2022-10-10 in ticks they are not, they show the same in the log, but inspecting the variables ValFrom, FileDate and ValTo in ticks they show : 1665442800000, 1665501208000, 1665442800000

The values from the DateTime.DateParse function return one value and the File.Lastmodified return another even if the dates are the same.

Any ideas ?
 

Pedro Caldeira

Active Member
Licensed User
Longtime User
solve it, by giving the value from File.LastModified to a string and then using the DateTime.DateParse with the string value.
 
Upvote 0

Knoppi

Active Member
Licensed User
Longtime User
LastModified represents ticks (date & time)
You can solve it like this
B4X:
    'Test Dates
    Dim lblUPLDataDesde As String ="2022-10-11"
    Dim lblUPLDataAte As String = "2022-10-11"
    Dim fname As String = "Testfile.txt"

    DateTime.DateFormat = "yyyy-MM-dd HH:mm:ss"
    Dim ValFrom As Long = DateTime.DateParse( lblUPLDataDesde &" 00:00:00")
    Dim ValTo As Long = DateTime.DateParse( lblUPLDataAte &" 23:59:59")
    Dim SharedFolder As String = File.DirApp
'    If (fname.ToLowerCase.EndsWith("lurl") Or fname.ToLowerCase.EndsWith("log") Or _
'    fname.ToLowerCase.EndsWith("svrlog") Or fname.ToLowerCase.EndsWith("json") Or _
'    fname.ToLowerCase.EndsWith("set")) Then
        Dim FileDate As Long = File.LastModified( SharedFolder, fname)
        Log($"LOG ValFrom:  $datetime{ValFrom}  ${ValFrom}"$)
        Log($"LOG FileDate: $datetime{FileDate}  ${FileDate}"$)
        Log($"LOG ValTo:    $datetime{ValTo}  ${ValTo}"$)
        If FileDate >= ValFrom And FileDate <= ValTo Then
        Log( $"ListFilesLOGS.Add: ${fname}"$)
'            ListFilesLOGS.Add(fname)
        End If
'    End If
 
Upvote 0
Top