Solved

Datediff issue with smalldatetime

Posted on 2012-03-16
1
505 Views
Last Modified: 2012-03-16
I have folowing code:

    SELECT @daysAgo=DATEDIFF(dd,LDatum, @LDatum) from LeistungenListe 

Open in new window


In DB LDatum has value '2011-07-04 00:00:00' now when I specify in my application as a date '2011-07-04 01:00:00' it returns me 1 day.

However when I specify '2011-07-03 12:00:00' I get 0 days. So it seems that somehow time 00:00 is treated as 23:59.

Is it right behaviour? How I can fix this without easy + 1 :)
0
Comment
Question by:ser_berto
1 Comment
 
LVL 26

Accepted Solution

by:
Chris Luttrell earned 500 total points
ID: 37731222
Check that you are not having a problem with timezone changes from your application to the database.  When tested straight in the databases the DATEDIFF functions correctly with both your test cases.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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