Date calculation Fails

Siam

Active Member
Licensed User
Longtime User
Hello,

i have a Problem to add one day to the 30.10.2011?!

if i use the same code and add one day to the 31.11.2011 then it works

i think this is a problem from b4a or?

here is my testcode:

B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim Startdatum,Datum_count As Long
   Dim label1, label2 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   label1.Initialize("")
   label2.Initialize("")
   activity.AddView(label1,0dip,0dip,300dip,120dip)
   activity.AddView(label2,0dip,100dip,300dip,220dip)
   
   DateTime.DateFormat = "dd.MM.yyyy"
   
   startdatum = DateTime.DateParse("30.10.2011")
   
   Datum_count = Startdatum
   datum_count = datum_count + DateTime.TicksPerDay
   
   label1.Text = "Startdatum:" & DateTime.Date(startdatum) & CRLF &"Startdatum + 1 Tag: " & DateTime.Date(datum_count)


   startdatum = DateTime.DateParse("31.10.2011")
   
   Datum_count = Startdatum
   datum_count = datum_count + DateTime.TicksPerDay
   
   label2.Text = "Startdatum:" & DateTime.Date(startdatum) & CRLF &"Startdatum + 1 Tag: " & DateTime.Date(datum_count)



End Sub

if i run this code then is the first calculation wrong! and the second is right.

i have a Screenshoot attached with the result of this program.

andy
 

Attachments

  • datefail.jpg
    datefail.jpg
    4.6 KB · Views: 232

Erel

B4X founder
Staff member
Licensed User
Longtime User
Which version of Basic4android are you using?
Please post the logs that you get for this code:
B4X:
Sub Globals
   Dim Startdatum,Datum_count As Long
   Dim label1, label2 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   DateTime.DateFormat = "dd.MM.yyyy"
   startdatum = DateTime.DateParse("30.10.2011")
   datum_count = Startdatum
   datum_count = datum_count + DateTime.TicksPerDay
   Log(DateTime.Date(datum_count) & " " & DateTime.Time(Datum_count))
   startdatum = DateTime.DateParse("31.10.2011")
   Datum_count = Startdatum
   datum_count = datum_count + DateTime.TicksPerDay
   Log(DateTime.Date(datum_count) & " " &  DateTime.Time(Datum_count))
End Sub

My result is:
B4X:
** Activity (main) Create, isFirst = true **
31.10.2011 00:00:00
01.11.2011 00:00:00
** Activity (main) Resume **
 

Siam

Active Member
Licensed User
Longtime User
Hello,

for this test Programm it works with the timezone!
but in my main Programm i use the dialogs library 2.7

if i put the DateTime.SetTimezone(0) in my code than i get trubble with the Datedialog.

for examble:

without set timezone(0)

i can enter date time and year

if i want to have the 21.10.2011
i enter 21.10.11


with set time zone (0)

i must add always one day more also

if i want to have the 21.10.2011
i must enter 22.10.11

... i hate the summer and winter time in europe....
 
Top