Android Question Find Difference between given date n current date

GudEvil

Member
Licensed User
Longtime User
I have to show a alert if given sql entry is atmost twodays old

i have date field in DB i
B4X:
                DateTime.dateFormat = "yyyy-mm-dd"
                Dim p As Period
                'values(1).text is date in sql 
p=DateUtils.PeriodBetween(DateTime.DateParse(values1(1).text),DateTime.DateParse(DateTime.Date(DateTime.Now)))

                Dim itt1 As Int=0
                itt1= p.Days*24*60 +p.Hours*60 +p.Minutes
                If itt1<= 2880 Then
                    g_panel2.AddView(values1(0),0,0,100%x,100%y)
                End If

but it shows all the time .

I debug the app n figure out that DateTime.Date(DateTime.Now)) give random date value. ???

why datetime.now() is not giving me todays date???
Is there way to achieve this?
 

Ed Brown

Active Member
Licensed User
Longtime User
Hi @GudEvil

This might be easier...

B4X:
    Dim p As Long
    p = Abs(DateTime.Now - DateTime.DateParse(values1(1).text))
    Dim itt1 As Int = p / DateTime.TicksPerDay
    If itt1<= 2880 Then
        g_panel2.AddView(values1(0),0,0,100%x,100%y)
    End If

The above will not care if the SQL date is before or after the current time. If you do care which way it is then you'll need to take out the Abs() function and update your If statement to also check if it is >= 0.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…