Android Question DateUtils.PeriodBetweenInDays/ a day end after 0 o clock

Alexander Stolte

Expert
Licensed User
Longtime User
Hello,

my problem is this output of this code.

B4X:
DateUtils.PeriodBetweenInDays(tformat,DateTime.Now).Days

For example i have this date

25.11.2017 14:00:00 and now is 26.11.2017 13:00:00 is the output = 0

What do I need to calculate around the time so that a new day begins after 0 o'clock?

Whatsapp for example it is 23:59 my message: "Today" now is it 00:00 and whatsapp say "yesterday" of my message.
 

DonManfred

Expert
Licensed User
Longtime User
What do you expect. From 14 to 13 o Clock on the next day. Te amount of days is 0 days, 23 hours.
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
This is my Problem with that:

Screenshot_20171126-133435-iloveimg-resized.png

I have 3 Dates, but because the function says 0 days and 23 hours it displays 2 Yesterdays. Is there a function that starts a new day from 0 o'clock or is based on the date?
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
I found a solution, but it was not easy to find:

B4X:
diff = DateUtils.PeriodBetweenInDays(StripTime(tformat),StripTime(DateTime.Now)).Days

Sub StripTime(Ticks As Long) As Long
    Return DateUtils.SetDateAndTime(DateTime.GetYear(Ticks), DateTime.GetMonth(Ticks), DateTime.GetDayOfMonth(Ticks), 0, 0, 0)
End Sub
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Seen someone else (here in the forums) use this trick to strip out the time portion :

B4X:
Sub StripTime(Ticks as Long) As Long
    Return(DateTime.DateParse(DateTime.Date(Ticks)))
End Sub
 
Upvote 0
Top