I try to find out how I can calculate the next day from a datetime string.
I have already a working calculation but that is based on datetime.now, code for that is:
B4X:
DateTime.date(DateTime.Add(DateTime.now,0,0,1))
Now, I have a string with format "2013-08-14 14:00:00" I'm looking for something like this:
There are two steps:
1. Parse the date and get the ticks value.
2. Add the required period.
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
Hi m643, something you need to do is very similar to the sample code below..Hope you can find your own way.
DateUtils is very helpful in this case...
Happy coding.
B4X:
Dim YourTime As Long = DateTime.Now
Dim YourNewTime As Long
Dim p1 As Period
p1.Days = 1
YourNewTime = DateUtils.AddPeriod(YourTime, p1)
EDIT: Sorry Erel I just posted few seconds after you, I don't know you already answered...
Erel: When I execute your code I get 1376568000000 but I need it in the same format "2013-08-15 14:00:00" (+1)
In my example in combination with Datetime.now I get it in the above format back.
I use the below code. It returns the correct answer, but it is interesting to see what Erel has to say about this:
B4X:
Dim s As String = "2013-08-14 14:00:00"
DateTime.DateFormat = "yyyy-MM-dd HH:mm:ss"
Dim tomorrow As Long=DateTime.Add(DateTime.DateParse(s),0,0,1)
Msgbox(DateTime.Date(tomorrow),"") 'returns 2013-08-15 14:00:00