Android Question understanding dates

Mark.S

Member
Licensed User
Why does this return "29/02/18"

Today =(DateTime.DateParse("28/02/18"))
Tomorrow = DateTime.Date(DateTime.Add(Today,0,0,1))

I need to increment (or decrement) the days by one
 

Mark.S

Member
Licensed User
I found Erel's post, relating to my exact need :)


B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim s As String = "2013-08-14 14:00:00"
   DateTime.DateFormat = "yyyy-MM-dd"
   DateTime.TimeFormat = "HH:mm:ss"
   Dim i As Int = s.IndexOf(" ")
   Dim ticks As Long = DateTime.DateTimeParse(s.SubString2(0, i), _
     s.SubString2(i + 1, s.Length))
   Dim p As Period
   p.Days = 1
   Dim tomorrow As Long = DateUtils.AddPeriod(ticks, p)
   Log(DateUtils.TicksToString(tomorrow))
End Sub
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Here is the exact answer to your question that does not involve the time and with your date format requested as shown :
B4X:
Dim Dorig As String=DateTime.DateFormat
    DateTime.dateformat="d/MM/yy"
    Dim intT As Long=(DateTime.DateParse("28/02/18"))
    Dim p As Period
    p.Days=1
    Dim t As Long = DateUtils.AddPeriod(intT, p)
    Dim Tomorrow As String=DateTime.Date(t)
    Log("tomorrow is: " & Tomorrow)  'displays 1/03/18
    DateTime.dateformat=Dorig
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
Why does this return "29/02/18"

Today =(DateTime.DateParse("28/02/18"))
Tomorrow = DateTime.Date(DateTime.Add(Today,0,0,1))

I need to increment (or decrement) the days by one

Try
B4X:
dim Today as long =(DateTime.DateParse("02/28/18"))
log("Tomorrow ="  & Log( DateTime.Date(DateTime.Add(today,0,0,1))))

it should return 03/01/0018
 
Upvote 0
Top