B4J Question Help With Parsing Dates

B4XDev

Member
Licensed User
Here's a test sub:

B4X:
Sub testDateFormats
    Private dstr As String
    Private dlong As Long
    Private mystr As String

    dstr = "3/28/2022"
    DateTime.DateFormat = "MM/dd/YYYY"
    dlong = DateTime.DateParse(dstr)
    DateTime.DateFormat = "YYYY.MM.dd"
    mystr = DateTime.Date(dlong)
    Log(dstr & " =? " & mystr)
End Sub

Here's the output:

B4X:
3/28/2022 =? 2022.12.26

I'm completely confused. Can anybody replicate this weirdness? And how do I fix it?
 

B4XDev

Member
Licensed User
I got it resolved, based on a clue from this thread.

Instead of the capital Y for the year, use lowercase... šŸ˜

I would have sworn I saw capital Ys in the examples!!! :oops: šŸ˜­
 
Last edited:
Upvote 0
Top