Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7531375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:09:14+00:00 2026-05-30T05:09:14+00:00

TL;DR version: Please confirm (or if not, provide assistance) that I’m getting SQL Server

  • 0

TL;DR version: Please confirm (or if not, provide assistance) that I’m getting SQL Server datetimeoffset data into my Joda Time Java objects correctly.


I’m in the middle of planning moving our database and Java code to be time-zone-aware. To accomplish this, I have been all over this post and am attempting to implement the best practices. Note that all code is considered “throw-away” code, so I’m not really concerned with efficiency here; just correctness.

Our environment consists of a Microsoft SQL Server 2008 database and a Java service layer whereby we access all data through stored procedures and Spring SimpleJdbcCall‘s.

One of the best practices mentioned is to use the Joda Time library. Since this is new to me, as is the datetimeoffset SQL datatype, I’d like to ensure that I’m doing this correctly (and thus not losing any information.)

Inside SQL Server, I created a table for testing all of the various SQL Server get-time-type functions:

CREATE TABLE MIKE_TEMP (
    ID INT NOT NULL IDENTITY,
    BLAH NVARCHAR(255),

    DT_GET_DATE DATETIME DEFAULT GETDATE() NOT NULL,
    DT_GET_UTC_DATE DATETIME DEFAULT GETUTCDATE() NOT NULL,
    DT_SYS_DATE_TIME DATETIME DEFAULT sysdatetime() NOT NULL,
    DT_SYS_UTC_DATE_TIME DATETIME DEFAULT sysutcdatetime() NOT NULL,
    DT_SYS_DATE_TIME_OFFSET DATETIME DEFAULT sysdatetimeoffset() NOT NULL,

    DTO_GET_DATE DATETIMEOFFSET DEFAULT GETDATE() NOT NULL,
    DTO_GET_UTC_DATE DATETIMEOFFSET DEFAULT GETUTCDATE() NOT NULL,
    DTO_SYS_DATE_TIME DATETIMEOFFSET DEFAULT sysdatetime() NOT NULL,
    DTO_SYS_UTC_DATE_TIME DATETIMEOFFSET DEFAULT sysutcdatetime() NOT NULL,
    DTO_SYS_DATE_TIME_OFFSET DATETIMEOFFSET DEFAULT sysdatetimeoffset() NOT NULL
);

Into this table, I added one value, blah = 'Hello World!'. The resulting data is:

ID BLAH         DT_GET_DATE         DT_GET_UTC_DATE     DT_SYS_DATE_TIME    DT_SYS_UTC_DATE_TIME DT_SYS_DATE_TIME_OFFSET DTO_GET_DATE                       DTO_GET_UTC_DATE                   DTO_SYS_DATE_TIME                  DTO_SYS_UTC_DATE_TIME              DTO_SYS_DATE_TIME_OFFSET           
-- ------------ ------------------- ------------------- ------------------- -------------------- ----------------------- ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- 
1  Hello World! 2012-02-15 08:58:41 2012-02-15 14:58:41 2012-02-15 08:58:41 2012-02-15 14:58:41  2012-02-15 08:58:41     2012-02-15 08:58:41.6000000 +00:00 2012-02-15 14:58:41.6000000 +00:00 2012-02-15 08:58:41.6005458 +00:00 2012-02-15 14:58:41.6005458 +00:00 2012-02-15 08:58:41.6005458 -06:00 

There is a corresponding stored procedure that simply does a select * from MIKE_TEMP and returns all data as output parameters.

The Java code that accesses this data is (only “interesting” imports included for clarity):

import org.joda.time.DateTime;
import java.util.Date;

@Component
public class MikeTempDaoImpl {
    private static final Logger logger = LoggerFactory.getLogger(MikeTempDaoImpl.class);

    private DataSource dataSource;

    @Autowired
    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    public DataSource getDataSource() {
        return dataSource;
    }

    public MikeVTemp getMikeTemp() {
        SimpleJdbcCall data = new SimpleJdbcCall(getDataSource());

        data.withProcedureName("get_MIKE_TEMP");
        data.withoutProcedureColumnMetaDataAccess();
        data.declareParameters(
                new SqlOutParameter("ID", Types.INTEGER),
                new SqlOutParameter("BLAH", Types.NVARCHAR),
                new SqlOutParameter("DT_GET_DATE", Types.TIMESTAMP),
                new SqlOutParameter("DT_GET_UTC_DATE", Types.TIMESTAMP),
                new SqlOutParameter("DT_SYS_DATE_TIME", Types.TIMESTAMP),
                new SqlOutParameter("DT_SYS_UTC_DATE_TIME", Types.TIMESTAMP),
                new SqlOutParameter("DT_SYS_DATE_TIME_OFFSET", Types.TIMESTAMP),
                new SqlOutParameter("DTO_GET_DATE", Types.TIMESTAMP),
                new SqlOutParameter("DTO_GET_UTC_DATE", Types.TIMESTAMP),
                new SqlOutParameter("DTO_SYS_DATE_TIME", Types.TIMESTAMP),
                new SqlOutParameter("DTO_SYS_UTC_DATE_TIME", Types.TIMESTAMP),
                new SqlOutParameter("DTO_SYS_DATE_TIME_OFFSET", Types.TIMESTAMP)
        );

        Map out;

        try {
            out = data.execute();
        } catch (Exception ex) {
            logger.error(ex.getMessage());
        }

        int id = (Integer) out.get("ID");
        String blah = (String) out.get("BLAH");
        DateTime dtGetDate = new DateTime((Date) out.get("DT_GET_DATE"));
        DateTime dtGetUtcDate = new DateTime((Date) out.get("DT_GET_UTC_DATE"));
        DateTime dtSysDateTime = new DateTime((Date) out.get("DT_SYS_DATE_TIME"));
        DateTime dtSysUtcDateTime = new DateTime((Date) out.get("DT_SYS_UTC_DATE_TIME"));
        DateTime dtSysDateTimeOffset = new DateTime((Date) out.get("DT_SYS_DATE_TIME_OFFSET"));
        DateTime dtoGetDate = new DateTime((Date) out.get("DTO_GET_DATE"));
        DateTime dtoGetUtcDate = new DateTime((Date) out.get("DTO_GET_UTC_DATE"));
        DateTime dtoSysDateTime = new DateTime((Date) out.get("DTO_SYS_DATE_TIME"));
        DateTime dtoSysUtcDateTime = new DateTime((Date) out.get("DTO_SYS_UTC_DATE_TIME"));
        DateTime dtoSysDateTimeOffset = new DateTime((Date) out.get("DTO_SYS_DATE_TIME_OFFSET"));

        MikeTemp mt = new MikeTemp.Builder()
                .id(id)
                .blah(blah)
                .dtGetDate(dtGetDate)
                .dtGetUtcDate(dtGetUtcDate)
                .dtSysDateTime(dtSysDateTime)
                .dtSysUtcDateTime(dtSysUtcDateTime)
                .dtSysDateTimeOffset(dtSysDateTimeOffset)
                .dtoGetDate(dtoGetDate)
                .dtoGetUtcDate(dtoGetUtcDate)
                .dtoSysDateTime(dtoSysDateTime)
                .dtoSysUtcDateTime(dtoSysUtcDateTime)
                .dtoSysDateTimeOffset(dtoSysDateTimeOffset)
                .build();

        System.out.println("id                   = [" + mt.getId() + "]");
        System.out.println("blah                 = [" + mt.getBlah() + "]");
        System.out.println("dtGetDate            = [" + mt.getDtGetDate() + "]");
        System.out.println("dtGetUtcDate         = [" + mt.getDtGetUtcDate() + "]");
        System.out.println("dtSysDateTime        = [" + mt.getDtSysDateTime() + "]");
        System.out.println("dtSysUtcDateTime     = [" + mt.getDtSysUtcDateTime() + "]");
        System.out.println("dtSysDateTimeOffset  = [" + mt.getDtSysDateTimeOffset() + "]");
        System.out.println("dtoGetDate           = [" + mt.getDtoGetDate() + "]");
        System.out.println("dtoGetUtcDate        = [" + mt.getDtoGetUtcDate() + "]");
        System.out.println("dtoSysDateTime       = [" + mt.getDtoSysDateTime() + "]");
        System.out.println("dtoSysUtcDateTime    = [" + mt.getDtoSysUtcDateTime() + "]");
        System.out.println("dtoSysDateTimeOffset = [" + mt.getDtoSysDateTimeOffset() + "]");

        return mvt;
    }
}

This is being exercised by a JUnit test:

@Test
public void testDateData() throws Exception {
    MikeTemp mt = dao.getMikeTemp();

    assertNotNull("MT should not be null, but it is.", mt);
    assertEquals(1, mt.getId());
    assertEquals("Hello World!", mt.getBlah());
}

And the results from all of the println’s are:

id                   = [1]
blah                 = [Hello World!]
dtGetDate            = [2012-02-15T08:58:41.577-06:00]
dtGetUtcDate         = [2012-02-15T14:58:41.577-06:00]
dtSysDateTime        = [2012-02-15T08:58:41.580-06:00]
dtSysUtcDateTime     = [2012-02-15T14:58:41.600-06:00]
dtSysDateTimeOffset  = [2012-02-15T08:58:41.600-06:00]
dtoGetDate           = [2012-02-15T08:58:41.600-06:00]
dtoGetUtcDate        = [2012-02-15T14:58:41.600-06:00]
dtoSysDateTime       = [2012-02-15T08:58:41.600-06:00]
dtoSysUtcDateTime    = [2012-02-15T14:58:41.600-06:00]
dtoSysDateTimeOffset = [2012-02-15T08:58:41.600-06:00]

Being as this server is in the US Central Time Zone, I definitely expect to see -06:00 for some of the results, but rather definitely not all of them. Have I missed something somewhere along the way? Is calling the Joda DateTime(Object) ctor with a java.util.Date object the correct thing to do in this situation? What else could/should I be doing that I’m not?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:09:16+00:00Added an answer on May 30, 2026 at 5:09 am

    No, this isn’t the way to do it. You’re using the DateTime(Object) constructor with a Date which only knows about an instant in time, and uses the system default time zone.

    As BalusC wrote, you could pass a Calendar into ResultSet.getTimestamp() if you want to specify the time zone yourself – but that’s not the same as preserving the information that’s already present in the database.

    It’s not clear which JDBC driver you’re using, and you’d probably have to move away from SimpleJdbcCall, but the Microsoft JDBC driver v3.0 has SQLServerCallableStatement.getDateTimeOffset (and ditto for SQLServerResultSet) which would presumably do the right thing. Given that your data type isn’t really portable, it means your code can’t really be either 🙁

    Do you definitely need to preserve the offset? If not, you could probably concentrate on getting the right instant out using the “normal” JDBC calls – which unfortunately it looks like it’s not doing at the moment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pick your version of SQL Server... if it has changed between version please specify
Can someone please confirm to me that when my application is written in .NET
I am using GNU Emacs 23.1.1. I used M-x org-version to confirm that I
Please share how you do version control for Lotus Notes/Domino development. I want to
Can someone please share a extremely simple version of JQuery Ajax with pagination??
I can't find the Html.Image method in new MVC RC version. Please somebody give
Version 1.0 of an application has a data model, which is saved/loaded using the
The version of Subclipse (1.2.4) currently available through Aptana's automatic Plugins Manager does not
What Python version can you please recommend for a long-term (years) project? Should one
Can somebody please tell me which version of Rebol 2 to use on CentOS?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.