Android Question Date stuck on 25-10-2020.

AHilberink

Active Member
Licensed User
Longtime User
Hi,

I have a strange behaviour, I cannot explain. I use a button Up and a button Down to increase/decrease the date with one day:
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Dim DisplayDatum As String
    Private edtDate As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    DateTime.DateFormat="dd-MM-yyyy"
    DisplayDatum=DateTime.Date(DateTime.Now)
    edtDate.Text=DisplayDatum
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btnDDmin_Click
    DisplayDatum=DateTime.Date(DateTime.DateParse(DisplayDatum)-DateTime.TicksPerDay*1)
    edtDate.Text=DisplayDatum
End Sub

Sub btnDDplus_Click
    DisplayDatum=DateTime.Date(DateTime.DateParse(DisplayDatum)+DateTime.TicksPerDay*1)
    edtDate.Text=DisplayDatum
End Sub

Suddenly it seems stuck on 25-10-2020. I can decrease, but not increase. Starting on 26-10-2020 I can increase. Decrease before 25-10-2020, it still get stuck on 25-10-2020.

Does this somethingto do with winter/summer time?
I am in the Netherlands (+2).

Attached you will find a small example.

Is there somthing I do wrong? Can someone have look and tell me what to do?

Thanks,
BR, André
 

Attachments

  • DateExample.zip
    3 KB · Views: 160

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Dim DisplayDatum As String
    Dim DiplayDateL As Long
    Private edtDate As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    DateTime.DateFormat="dd-MM-yyyy"
    DiplayDateL = DateTime.Now
    DisplayDatum=DateTime.Date(DateTime.Now)
    edtDate.Text=DisplayDatum
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btnDDmin_Click
    DiplayDateL = DateTime.Add(DiplayDateL,0,0,-1)
    edtDate.Text=DateTime.Date(DiplayDateL)

End Sub

Sub btnDDplus_Click
    DiplayDateL = DateTime.Add(DiplayDateL,0,0,1)
    edtDate.Text=DateTime.Date(DiplayDateL)
End Sub
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Dim DisplayDatum As String
    Dim DiplayDateL As Long
    Private edtDate As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    DateTime.DateFormat="dd-MM-yyyy"
    DiplayDateL = DateTime.Now
    DisplayDatum=DateTime.Date(DateTime.Now)
    edtDate.Text=DisplayDatum
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btnDDmin_Click
    DiplayDateL = DateTime.Add(DiplayDateL,0,0,-1)
    edtDate.Text=DateTime.Date(DiplayDateL)

End Sub

Sub btnDDplus_Click
    DiplayDateL = DateTime.Add(DiplayDateL,0,0,1)
    edtDate.Text=DateTime.Date(DiplayDateL)
End Sub

Thanks DonManfred. I changed it in my project and it works fine. This is a perfect solution.
Still wondering why my solution get stuck suddenly.

BR, André
 
Upvote 0
Top