I don’t have a solution to the problem but I do have some more info about how it happened for me, and also example code to fix the dates.
Windows 11, Libreoffice 7.6.4.1 64-bit Embedded HSQLDB 1.8.0.10, Timezone Sydney Australia GMT+11 in DST.
I went back thru all my backups of my Base database, and all the dates in all my tables (I have no Date/Time or Time columns in my database), were suddenly 1 day less than they should be.
This happened on 12th Feb 2024 backup taken 3:38pm while I was on a cruise boat going from Australila to NZ. I’m not 100% sure but I may have changed the Timezone on my pc from Australia to NZ just before this happened. I’m don’t know if the date is supposed to change when the timezone changes, but as NZ time is 2 hours before Sydney time, the date should not have changed anyway.
As there is no DateAdd function in HSQLDB 1.8.0.10 and the dates covered a large date range, I couldn’t fix the dates using an SQL statement. I wrote a form with a button for each table and a
Basic Macro for each table to iterate thru all the rows and fix all the dates.
There is a DateAdd function in Libreoffice 7.6.4.1 but I didn’t use it as Basic handles adding/subtracting days to a Basic date because that date is just a Double where the integer part is the no of days since
30/12/1899.
I’m giving my example code here as it took me quite a while to figure out how to update a RowSet and to handle null columns. I’d be happy to hear of any improvements to my code.
Sub btnShares_ExecuteAction( oEvent as object)
' add 1 day to Shares.AcqDate, Shares.SaleDate
dim oRowSet as Object ’ must be RowSet not ResultSet to update
Dim oColumn as object ’ column of database row
Dim dbDate As New com.sun.star.util.Date ’ Database date or form Date Control (bound)
Dim basDate as Date ’ Basic Date: integer no of days since 30/12/1899
Dim intRowsUpdated as integer
' msgbox doc:
' https://help.libreoffice.org/7.6/en-GB/text/sbasic/shared/03010102.html?DbPAR=BASIC#bm_id3153379
if msgbox("Update Shares.AcqDate & Shares.SaleDate? (take a backup first!)", MB_OKCANCEL, "Fix Dates") = IDOK then
oRowSet = createUnoService( "com.sun.star.sdb.RowSet" )
With oRowSet
.DataSourceName="[Registered DataBaseName]"
.CommandType=com.sun.star.sdb.CommandType.COMMAND
' Create oRowSet in Descending Date order so there is no possibility of violating
' a duplicate key constraint by changing a date to one that already
' exists because we have not updated it yet
.Command = "SELECT ""Shares"".""Investor"", ""Shares"".""Company"", ""Shares"".""CertNo""," _
& " ""Shares"".""AcqDate"", ""Shares"".""SaleDate""" _
& " FROM ""Shares""" _
& " ORDER BY ""Shares"".""Investor"" ASC,""Shares"".""Company"" ASC, ""Shares"".""CertNo"" ASC," _
& " ""Shares"".""AcqDate"" DESC"
.execute()
if oRowSet.RowCount = 0 then
msgbox "No rows in Shares oRowSet"
exit sub
end if
Do while .next
'if .Row > 20 then ' testing
' exit Do
'end if
'if .IsFirst() then ' testing
' 'do_MRI(oRowSet)
'end if
' AcqDate
oColumn = .Columns.getByName("AcqDate")
dbDate = oColumn.GetDate()
' Add 1 day to AcqDate
basDate = DateSerial( dbDate.Year, dbDate.Month, dbDate.Day) + 1
dbDate.Year = Year ( basDate)
dbDate.Month = Month( basDate)
dbDate.Day = Day ( basDate)
oColumn.updateDate(dbDate)
'SaleDate - may be NULL
oColumn = .Columns.getByName("SaleDate")
dbDate = oColumn.GetDate()
if oColumn.wasNull() then ' last column gotten was null. MUST do 'get' before checking wasNull()
msgbox "SaleDate was NULL - no action"
else
' Add 1 day to SaleDate
basDate = DateSerial( dbDate.Year, dbDate.Month, dbDate.Day) + 1
MyMsgBox "btnShares_ExecuteAction SaleDate dbDate=" & dbDate.Year & "-" _
& dbDate.Month & "-" & dbDate.Day & " basDate=" & basDate
dbDate.Year = Year ( basDate)
dbDate.Month = Month( basDate)
dbDate.Day = Day ( basDate)
oColumn.updateDate(dbDate)
end if
.updateRow()
intRowsUpdated = intRowsUpdated + 1
Loop
End With
msgbox "Rows Updated: " & intRowsUpdated
end if
End Sub