Android Question [SOLVED] Period not returning expected result.

ProjectGroup19

Active Member
Licensed User
B4X:
Dim  CurrentDate As Long =DateTime.Now
Log(CurrentDate): 1624961984591

Dim check As Long=DateUtils.SetDate("2021","06","30")
Log(check): 1625011200000

Dim  DateCheck As Period=DateUtils.PeriodBetweenInDays(CurrentDate,check)
Log(DateCheck): [Days=0, Hours=13, IsInitialized=true, Minutes=40, Months=0, Seconds=15, Years=0]
 
Last edited:
Solution
If you want the difference to be 1, you can do this:, by excluding the time component from today's date
B4X:
Dim CurrentDate As Long =DateTime.DateParse(DateTime.Date(DateTime.Now))

This worked as expected

B4X:
Dim check As Long=DateUtils.SetDateAndTime("2021","06","30",23,59,0)
This is what i did earlier..It also worked as expected.

Mahares

Expert
Licensed User
Longtime User
Midnight as time component??
When you start typing DateUtils.SetDate( you will see in the intellisense that it tells you the time will be 00:00:00
You were not comparing the 2 dates with respect to the same exact time slot of the day.
DateTime.Now means more than today. It means today plus the time you took the reading which changes every second
 
Upvote 0

ProjectGroup19

Active Member
Licensed User
When you start typing DateUtils.SetDate( you will see in the intellisense that it tells you the time will be 00:00:00
You were not comparing the 2 dates with respect to the same exact time slot of the day.
Ohk, i get you now. it's assumed that a new day has started due to the time part 00:00:00.
Thank you very much
 
Upvote 0

ProjectGroup19

Active Member
Licensed User
If you want the difference to be 1, you can do this:, by excluding the time component from today's date
B4X:
Dim CurrentDate As Long =DateTime.DateParse(DateTime.Date(DateTime.Now))

This worked as expected

B4X:
Dim check As Long=DateUtils.SetDateAndTime("2021","06","30",23,59,0)
This is what i did earlier..It also worked as expected.
 
Upvote 0
Solution
Top