error count days between dates

mike2ppc

Member
Licensed User
Longtime User
Hello together,

I'm trying to calc the total of days between two dates.
When I'm running the source in the dev IDE all works fine,
but after compiling and executing the comp version I got
a error message '...Input String was not in correct format ...'
Please see attache source and compile it and execute the
exe file.

click button 'Count ....'

Best Regards

Michael
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
The problem is with this line:
B4X:
textBox3.text = textBox3.Text + 1
Unlike regular variables, you need to first assign 0 to the textbox.

However your code will still not work correctly.
Dates are stored as ticks which are very big numbers and small rounding errors may occur during calculations. The result is that start_date may not be exactly equal to end_date and the loop will not stop.

The simple solution from the http://www.b4x.com/forum/tutorials/894-date-time.html tutorial is
B4X:
[COLOR=#010101]d1 = [COLOR=#0000ff]DateParse[/COLOR]([COLOR=#800000]"04/30/2006"[/COLOR])
d2 = [COLOR=#0000ff]DateParse[/COLOR]([COLOR=#800000]"04/30/2007"[/COLOR])
[COLOR=#0000ff]Msgbox[/COLOR]([COLOR=#0000ff]Int[/COLOR]((d2-d1)/cTicksPerDay))
[/COLOR]
 
Top