Hibernate returning incorrect date value from Sql Server

Posted on 2006-04-19
Last Modified: 2012-08-14
Hello - I have a Sql Server database that has a column with a field type of "datetime", which is filled with values automatically by hibernate's timestamp.  One record is stored with the value "4/19/2006 9:45:00 AM", but when I retrieve the object from hibernate and use a get method, it returns a different datetime (when I format the output, it looks like this: "04/18/2006 06:00:00 AM").  I want to use the Calendar object to check if a date I have is after the value in the database, but I am getting incorrect output because the date is being returned to me wrong.

I'd appreciate your help!
Question by:sb1977
    LVL 30

    Expert Comment

    Maybe its a problem with the Locale. Where is the DB server running and where is the application running? Are they on 2 different time zones?

    Author Comment

    That's a good point, I'll look into it some more.  However, even if it were in a different time zone, the minutes would be the same.  The strange thing about this issue is that hibernate is setting and getting the field from my Java application, but the values are different.
    LVL 30

    Accepted Solution

    However the time difference looks to be more than 24 hours so its doubtful if time zones are causing the problem.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now