Android Question Bring a date a day before - jRDC2

Bladimir Silva Toro

Active Member
Licensed User
Hello friends

When I make a date query to a database, the day that appears is January 15, 2021 (2021-01-15). View image.

1613079288811.png


When I make this query for this date in B4A it corresponds to the number: 1610668800000

This date is then converted to text and shows that it corresponds to a day before (2021-01-14)

B4X:
FechaExp = records(result.Columns.Get("FechaExp"))
DateTime.DateFormat = "MM/dd/yyyy"
FechaTexto = DateTime.Date(FechaExp)

Why is this happening, why is this error?

Note: jRCD2 connection to a Microsoft SQL Server database on an Ubuntu server.
 

Jeffrey Cameron

Well-Known Member
Licensed User
What is the declared type of "FechaExp?" Add a log statement after your "FechaExp = " statement to display the value.
I assume that "records" is a function/map, so what does the key value for that date actually contain/return?
 
Last edited:
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
1. Again, try logging the contents of "result.columns.get("FechaExp")" to see what you're actually getting from the SQL server.
2. What does the function "records(...)" do?

Assuming that the value in the column is correct, the records() must be altering it, or it's a UTC vs. local time issue:
B4X:
    Dim plVal As Long = 1610668800000
    Log("My offset: " & DateTime.Date(plVal) & " @ " & DateTime.Time(plVal))
    Dim piZone As Int = DateTime.TimeZoneOffset
    Dim psCurrVals() As String = Array As String(DateTime.DateFormat, DateTime.TimeFormat)
    DateTime.SetTimeZone(0)
    DateTime.DateFormat = "MM/dd/yyyy"
    DateTime.TimeFormat = "HH:mm:ss"
    Log("UTC: " & DateTime.Date(plVal) & " @ " & DateTime.Time(plVal))
    DateTime.SetTimeZone(piZone)
    DateTime.DateFormat = psCurrVals(0)
    DateTime.TimeFormat = psCurrVals(1)
B4X:
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
My offset: 01/14/2021 @ 19:00:00
UTC: 01/15/2021 @ 00:00:00
** Activity (main) Resume **
 
Last edited:
Upvote 0
Top