Android Question displaying date

ANGELINE ROMAN

Member
Licensed User
example date "04/20/2019"
when you add 3 days the new date is "04/23/2019"
can somebody help me a b4a code that will display the original date and the new date
 

mangojack

Well-Known Member
Licensed User
this is a long-winded but simple example ....

B4X:
DateTime.DateFormat = "MM/dd/yyyy"
Dim sFirstDate, sLastDate  As String
Dim lFirstDate, lLastDate As Long
 
sFirstDate = "04/20/2019"
lFirstDate = DateTime.DateParse(sFirstDate)            'convert string date to ticks
lLastDate = lFirstDate + (DateTime.TicksPerDay * 3)    'add equivilent of 3 days ticks
sLastDate = DateTime.Date(lLastDate)                   'convert total ticks back to a string value
 
Log(sLastDate)

Also see this .. https://www.b4x.com/android/forum/threads/b4x-dateutils-simplifies-date-and-time-calcuations.26290/

Also see this Video Tutorial ... Erel Teaches Date & Time ...

Also search for "DateTime" to see many posts and study the various code

I could not find any example in any of the guides .. but someone might correct me.


ps: also have a look here .. a reply in a similar thread today by @emexes ...
https://www.b4x.com/android/forum/threads/days-of-the-week.105341/#post-660068
 
Last edited:

Erel

Administrator
Staff member
Licensed User
B4X:
DateTime.DateFormat = "MM/dd/yyyy"
Dim sFirstDate, sLastDate  As String
Dim lFirstDate, lLastDate As Long
sFirstDate = "04/20/2019"
lFirstDate = DateTime.DateParse(sFirstDate)            'convert string date to ticks
Dim p As Period
p.Days = 3
lLastDate = DateUtils.AddPeriod(lFirstDate, p)    'add equivalent of 3 days ticks
sLastDate = DateTime.Date(lLastDate)                   'convert total ticks back to a string value
Log(sLastDate)
 
Top