0

I have a SQL Server database where some columns have a datetime type but store only a date with the time parts all being zero.

A Java web app running on WebSphere Portal uses JSF and Hibernate to read the SQL data and output to HTML. Date columns as above are having the date displayed as the previous day. Which component causes this, and how should I fix it?

Implementation details follow.

A column in SQL Server has type datetime, and contains data like 2020-02-01 00:00:00.000.

The Hibernate table definition has this as a key column with type java.sql.Timestamp.

<key-property name="contractBeginDate" column="Contract_Begin" type="java.sql.Timestamp" length="23">
    <meta attribute="field-description">
        @hibernate.property
        column="Contract_Begin"
        length="23"
    </meta>
</key-property>

The Hibernate query to get data is defined as follows.

<query name="getSalesConsultantServiceContractsSold_agreementDate_asc" cacheable="false"><![CDATA[
    FROM VServiceAgreementsList vsal
    WHERE vsal.slmsCode = :slmsCode
    AND vsal.teamEliteYear = :year
    ORDER BY vsal.contractBeginDate ASC
]]></query>

The Java class for the table uses the java.util.Date type for the field and get-method for that column.

Finally, a JSP file with a backing bean produces the HTML output, with the following contained in a column of a dataTable.

<h:outputText id="text8" value="#{varServiceAgreementSalesList.contractBeginDate}" styleClass="outputText">
    <f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>

The data example given above is output as 31/01/2020, one day before the correct date.
I assume a time-zone difference is involved somehow.
All users are in Australia and probably have their PC time-zones set anywhere from UTC+8 to UTC+11, so maybe the original value is being interpreted as the local time-zone, translated to UTC (which will be the previous day), then having the time cut off.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Scott Leis
  • 2,810
  • 6
  • 28
  • 42
  • I don't know enough about your components to answer, but what I can say is that if you send a datetime value to a browser using JSON and then convert it into a JavaScript object, it will automatically be adjusted by the local timezone. Its a right PITA. So not sure if that is what you are facing, but just throwing it out there. – Dale K Jan 28 '21 at 01:21
  • 1
    *"All users are in Australia and probably have their PC time-zones set anywhere from UTC+8 to UTC+11"* FYI: Java/JSF runs in webserver not in webbrowser. – BalusC Jan 28 '21 at 09:29

1 Answers1

0

Trie set websphere location as the same as SQL Server