Calculating the end date by adding days

GMan

Well-Known Member
Licensed User
Longtime User
Hello,

i have 4 Start days (i dont need hours, minutes & seconds) and each of them CAN have a different value.
For each of these 4 dates i want to add a timespan in full days (i.e. Number 1 = 90, Number 2 = 60 etc.)

Now i (simple) want to add the days to the relating start dates and displaying the end date.
The parameters like Start date and number of days is saved as a map via the Setup-Part of the app and works fine.

I tried some sample codes from DateUtils and here is my code so far:
(The declarations (DIM) as Label, Label and Int is done in the header)

Code: Copy
sets = File.ReadMap(File.DirRootExternal, "test1.map")
MyLabel1.Text   = sets.Get("Textlabel1")
MyLabel1Startdate.Text = sets.Get("sDate1")  ' i.e. 17.02.2013
MyLabel1days.Text = sets.Get("Days1")          ' i.e. 90 (days)
AddPeriod(MyLabel1Startdate.Text,MyLabel1days)

The following error occurs:
..."unparseable date": 17.02.2013

Is it because i am using not the US-format 02/17/13 or Feb 17 13 ?
And if, can i change (via B4A) the format so that it fits ?

I also tried out several variations from the samples, without success :confused:
I code normally in visual basic and i am just a Newbie here .

Thx in advance
Gman

(Sorry for my english, its not my native language :-))
 
Last edited:
Thx for your quick reply.

i'm not writing in the DateUtils module.

MyLabel1Days is the number of days, here 90 and was read from the map file.
As i understood the format has to be (abstract) (Start date, number of days to be added)

After setting the date format another error occurs:

Code: Copy
error: inconvertible types
_addperiod((long)(Double.parseDouble(mostCurrent._myLabel1startdate.getText())),(test.app.dateutils._period)(90));
                                                                                                             ^
  required: _period
  found:    int

i declared the MyLabel1days as an Int(eger), in this case 90
 
Last edited:
Upvote 0
i tried this also, the result is nearly the same:

Code: Copy
error: inconvertible types
mostCurrent._dateutils._addperiod(mostCurrent.activityBA,(long)(Double.parseDouble(mostCurrent._myLabel1startdate.getText())),(test.app.dateutils._period)(90));
                                                                                                                                                           ^
  required: _period
  found:    int
1 error

i know what you mean, but i copied the section from the DateUtils module to the main app - so it was called without using the module
 
Upvote 0
Thx a lot, that sample solves my problem so far:
Code: Copy
MyLabel1Enddate.Text = DateUtils.TicksToString(NewDate)

The label is filles with the correct end date in the correct format, BUT behind this the time appeares as 00:00:00

Is there a kind of RTrim command to cut the time part ?
 
Upvote 0
I found it out, yes.

i "stripped" the Function in the DateUtils and cutted the part
Code: Copy
... & " " & DateTime.Time(Ticks)

Thx a lot for your help :icon_clap:

Now i want to calculate the period FROM StartDate1 and the period UNTIL EndDate1, both also as a simple int (without time again)
 
Upvote 0
Find it out myself :cool:

Code: Copy
MyLabel1DaysSince.Text = DateUtils.PeriodBetweenInDays(StartDate,DateTime.Now)
MyLabel1DaysSince.Text = MyLabel1DaysSince.Text.SubString2(6,8)

The result without the second line was
Days=40
Hours=2

So i used the second line to get the correct substring (40) from that string.
In case they are never greater than 2 digits i have no problem with that - but what if it is only 1 letter ?

Now i'll try to get the days UNTIL EndDate1 ...which was pretty easy.

I simply did this:
Code: Copy
MyLabel1DaysUntil.Text = DateUtils.PeriodBetweenInDays(DateTime.Now, EndDate)
MyLabel1DaysUntil.Text = MyLabel1DaysUntil.Text.SubString2 (6,8)

So, solved so far except the prob when there is only one digit (0-9 days)
 
Last edited:
Upvote 0
Back
Top