SELECT statement from MS SQL returns dates with loss of 2-4 days









up vote
1
down vote

favorite












I use MS SQL Express 2014 to store some data.
I have 3 different tables, each of them contains a DATE type field.
When I do a select statement to each table via JDBC, the ResultSet in some cases returns dates with loss of 2-4 days.



The code looks like:



ResultSet rs = preparedStatement.executeQuery();
while(rs.next())
java.sql.Date date = rs.getDate("DATE");



Dates in DB looks like: "1942-06-10", "1938-03-15", etc. The loss happens only sometimes, no matter how the date looks. On Java side they become "1942-06-08" or "1938-03-11".



I can't understand the reason of the problem, because
in some cases "date" contains the exact data as field in DB,
and in other cases "date" is losing from 2 to 4 days comparing to DB field.
Thank you!










share|improve this question









New contributor




ReemuS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 3




    Could you add example dates from your DB for both cases, along with the result on java side ?
    – Arnaud
    22 hours ago






  • 1




    Just check the timezone for the both DB
    – SaviNuclear
    22 hours ago










  • The dates where the loss happens, are they historic dates, say, more than 100 years ago? Does the loss always happen for dates in that range or only sometimes? Do you get the same loss if you try LocalDate date = rs.getObject("DATE", LocalDate.class) instead? (The java.sql.Date class is outdated and has some design issues to it, so all things being equal I would recommend the latter approach.)
    – Ole V.V.
    22 hours ago







  • 1




    Dates in DB looks like: "1942-06-10", "1938-03-15", etc. The loss happens only sometimes, no matter how the date looks. On Java side they become "1942-06-08" or "1938-03-11".
    – ReemuS
    22 hours ago






  • 1




    Welcome to Stack Overflow. This is vuja de (never seen it before). Please show your query and a few rows of sample data illustrating the problem. You can edit your question to do this.
    – O. Jones
    19 hours ago














up vote
1
down vote

favorite












I use MS SQL Express 2014 to store some data.
I have 3 different tables, each of them contains a DATE type field.
When I do a select statement to each table via JDBC, the ResultSet in some cases returns dates with loss of 2-4 days.



The code looks like:



ResultSet rs = preparedStatement.executeQuery();
while(rs.next())
java.sql.Date date = rs.getDate("DATE");



Dates in DB looks like: "1942-06-10", "1938-03-15", etc. The loss happens only sometimes, no matter how the date looks. On Java side they become "1942-06-08" or "1938-03-11".



I can't understand the reason of the problem, because
in some cases "date" contains the exact data as field in DB,
and in other cases "date" is losing from 2 to 4 days comparing to DB field.
Thank you!










share|improve this question









New contributor




ReemuS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 3




    Could you add example dates from your DB for both cases, along with the result on java side ?
    – Arnaud
    22 hours ago






  • 1




    Just check the timezone for the both DB
    – SaviNuclear
    22 hours ago










  • The dates where the loss happens, are they historic dates, say, more than 100 years ago? Does the loss always happen for dates in that range or only sometimes? Do you get the same loss if you try LocalDate date = rs.getObject("DATE", LocalDate.class) instead? (The java.sql.Date class is outdated and has some design issues to it, so all things being equal I would recommend the latter approach.)
    – Ole V.V.
    22 hours ago







  • 1




    Dates in DB looks like: "1942-06-10", "1938-03-15", etc. The loss happens only sometimes, no matter how the date looks. On Java side they become "1942-06-08" or "1938-03-11".
    – ReemuS
    22 hours ago






  • 1




    Welcome to Stack Overflow. This is vuja de (never seen it before). Please show your query and a few rows of sample data illustrating the problem. You can edit your question to do this.
    – O. Jones
    19 hours ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I use MS SQL Express 2014 to store some data.
I have 3 different tables, each of them contains a DATE type field.
When I do a select statement to each table via JDBC, the ResultSet in some cases returns dates with loss of 2-4 days.



The code looks like:



ResultSet rs = preparedStatement.executeQuery();
while(rs.next())
java.sql.Date date = rs.getDate("DATE");



Dates in DB looks like: "1942-06-10", "1938-03-15", etc. The loss happens only sometimes, no matter how the date looks. On Java side they become "1942-06-08" or "1938-03-11".



I can't understand the reason of the problem, because
in some cases "date" contains the exact data as field in DB,
and in other cases "date" is losing from 2 to 4 days comparing to DB field.
Thank you!










share|improve this question









New contributor




ReemuS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I use MS SQL Express 2014 to store some data.
I have 3 different tables, each of them contains a DATE type field.
When I do a select statement to each table via JDBC, the ResultSet in some cases returns dates with loss of 2-4 days.



The code looks like:



ResultSet rs = preparedStatement.executeQuery();
while(rs.next())
java.sql.Date date = rs.getDate("DATE");



Dates in DB looks like: "1942-06-10", "1938-03-15", etc. The loss happens only sometimes, no matter how the date looks. On Java side they become "1942-06-08" or "1938-03-11".



I can't understand the reason of the problem, because
in some cases "date" contains the exact data as field in DB,
and in other cases "date" is losing from 2 to 4 days comparing to DB field.
Thank you!







java sql-server date datetime






share|improve this question









New contributor




ReemuS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




ReemuS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 19 hours ago





















New contributor




ReemuS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 22 hours ago









ReemuS

92




92




New contributor




ReemuS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





ReemuS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






ReemuS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 3




    Could you add example dates from your DB for both cases, along with the result on java side ?
    – Arnaud
    22 hours ago






  • 1




    Just check the timezone for the both DB
    – SaviNuclear
    22 hours ago










  • The dates where the loss happens, are they historic dates, say, more than 100 years ago? Does the loss always happen for dates in that range or only sometimes? Do you get the same loss if you try LocalDate date = rs.getObject("DATE", LocalDate.class) instead? (The java.sql.Date class is outdated and has some design issues to it, so all things being equal I would recommend the latter approach.)
    – Ole V.V.
    22 hours ago







  • 1




    Dates in DB looks like: "1942-06-10", "1938-03-15", etc. The loss happens only sometimes, no matter how the date looks. On Java side they become "1942-06-08" or "1938-03-11".
    – ReemuS
    22 hours ago






  • 1




    Welcome to Stack Overflow. This is vuja de (never seen it before). Please show your query and a few rows of sample data illustrating the problem. You can edit your question to do this.
    – O. Jones
    19 hours ago












  • 3




    Could you add example dates from your DB for both cases, along with the result on java side ?
    – Arnaud
    22 hours ago






  • 1




    Just check the timezone for the both DB
    – SaviNuclear
    22 hours ago










  • The dates where the loss happens, are they historic dates, say, more than 100 years ago? Does the loss always happen for dates in that range or only sometimes? Do you get the same loss if you try LocalDate date = rs.getObject("DATE", LocalDate.class) instead? (The java.sql.Date class is outdated and has some design issues to it, so all things being equal I would recommend the latter approach.)
    – Ole V.V.
    22 hours ago







  • 1




    Dates in DB looks like: "1942-06-10", "1938-03-15", etc. The loss happens only sometimes, no matter how the date looks. On Java side they become "1942-06-08" or "1938-03-11".
    – ReemuS
    22 hours ago






  • 1




    Welcome to Stack Overflow. This is vuja de (never seen it before). Please show your query and a few rows of sample data illustrating the problem. You can edit your question to do this.
    – O. Jones
    19 hours ago







3




3




Could you add example dates from your DB for both cases, along with the result on java side ?
– Arnaud
22 hours ago




Could you add example dates from your DB for both cases, along with the result on java side ?
– Arnaud
22 hours ago




1




1




Just check the timezone for the both DB
– SaviNuclear
22 hours ago




Just check the timezone for the both DB
– SaviNuclear
22 hours ago












The dates where the loss happens, are they historic dates, say, more than 100 years ago? Does the loss always happen for dates in that range or only sometimes? Do you get the same loss if you try LocalDate date = rs.getObject("DATE", LocalDate.class) instead? (The java.sql.Date class is outdated and has some design issues to it, so all things being equal I would recommend the latter approach.)
– Ole V.V.
22 hours ago





The dates where the loss happens, are they historic dates, say, more than 100 years ago? Does the loss always happen for dates in that range or only sometimes? Do you get the same loss if you try LocalDate date = rs.getObject("DATE", LocalDate.class) instead? (The java.sql.Date class is outdated and has some design issues to it, so all things being equal I would recommend the latter approach.)
– Ole V.V.
22 hours ago





1




1




Dates in DB looks like: "1942-06-10", "1938-03-15", etc. The loss happens only sometimes, no matter how the date looks. On Java side they become "1942-06-08" or "1938-03-11".
– ReemuS
22 hours ago




Dates in DB looks like: "1942-06-10", "1938-03-15", etc. The loss happens only sometimes, no matter how the date looks. On Java side they become "1942-06-08" or "1938-03-11".
– ReemuS
22 hours ago




1




1




Welcome to Stack Overflow. This is vuja de (never seen it before). Please show your query and a few rows of sample data illustrating the problem. You can edit your question to do this.
– O. Jones
19 hours ago




Welcome to Stack Overflow. This is vuja de (never seen it before). Please show your query and a few rows of sample data illustrating the problem. You can edit your question to do this.
– O. Jones
19 hours ago

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






ReemuS is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222221%2fselect-statement-from-ms-sql-returns-dates-with-loss-of-2-4-days%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








ReemuS is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















ReemuS is a new contributor. Be nice, and check out our Code of Conduct.












ReemuS is a new contributor. Be nice, and check out our Code of Conduct.











ReemuS is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222221%2fselect-statement-from-ms-sql-returns-dates-with-loss-of-2-4-days%23new-answer', 'question_page');

);

Post as a guest














































































這個網誌中的熱門文章

How to combine Bézier curves to a surface?

Mutual Information Always Non-negative

Why am i infinitely getting the same tweet with the Twitter Search API?