Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [datetime2]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
14 votes
1 answer
868 views

Incorrect comparison of datetime and datetime2

I know that it is not a good practice to have an implicit type convert. But this is really unexpected behavior when a lower value can suddenly become higher. declare @LastSelectedDate DATETIME = '2021-...
user avatar
0 votes
1 answer
48 views

Why some triggers run exactly at the same time?

I wrote a simple audit with triggers. when a trigger called, the data inside the trigger (inserted and deleted rows) are sent through broker to a procedure to write them in the Master Audit Table. ...
user avatar
0 votes
0 answers
87 views

SQL Server database restore from backup changes all dates with datetime2 type return with values to future dates

I'm trying to restore a SQL Server database from a .bak file. The process completes without any issues, but the dates with datatype datetime2 are presented with totally different values (change to ...
user avatar
-3 votes
1 answer
13k views

Operand type clash: int is incompatible with datetime2

The code below generates this error: ERROR Msg 206, Level 16, State 2, Procedure usp_TRAC_PSE_Step_12_Resource_Request_OBJECT-Production-Part1, Line 93 Operand type clash: int is incompatible with ...
user avatar
0 votes
1 answer
721 views

The datediff function resulted in an overflow. But should not

I have this stored procedure in SQL-Server 2014 USE [provbank] GO /****** Object: StoredProcedure [dbo].[GetHBSeconds] Script Date: 2018-10-05 08:40:07 ******/ SET ANSI_NULLS ON GO SET ...
user avatar
4 votes
1 answer
1k views

What does 0 in DATEDIFF(MINUTE, 0, <Date>) actually mean?

So, our data team asked for some help in solving a problem they had. I eventually tracked it down to some really out of range data (1/1/0001) and a DATEDIFF function they were using. While I've ...
user avatar
3 votes
1 answer
632 views

SQL Server 2016 Compatibility Level and Datetime 2

We have been running SQL Server 2016 for some time now but initially left the database compatibility level to SQL Server 2008 (100). Recently we did update the DB Compatibility Level to 2016 (130) but ...
user avatar
  • 170
3 votes
2 answers
4k views

Calculate total hours per day based on "TIME_IN" data in one row and "TIME_OUT" data on the next row

I need to calculate the actual time spent in the office per day. I have seen several examples online, but they all have TIME_IN and TIME_OUT in the same row. My application puts entries into a new ...
user avatar
3 votes
2 answers
745 views

12 fraction digits in SQL Server

We are currently migrating from DB2 to SQL Server. DB2 supports TIMESTAMP(6-12) while DATETIME2 only supports up to 7 decimals. Since we have many keys represented as TIMESTAMP(12) what would be the ...
user avatar
4 votes
2 answers
2k views

Datetime2 rounding issue

We are working on a multi-database application (read and write to multiple databases). The datamodel is identical on the databases. We are inserting a timestamp (12 fraction digits) value in a ...
user avatar
0 votes
1 answer
2k views

How to set datetime2 to mandate?

I want to create a SQL Script to clean datetime2 field and set it up to datetime2 begin '1-1-0001 12:00:00'. How to set GETDATE() to '1-1-0001 12:00:00' instead of using convert function ? UPDATE ...
user avatar
18 votes
1 answer
16k views

datetime2(0) vs datetime2(2)

According to the documentation datetime2 (Transact-SQL): Storage size 6 bytes for precisions less than 3. 7 bytes for precisions 3 and 4. All other precisions require 8 bytes. The size of ...
user avatar
2 votes
1 answer
6k views

Help with out-of-range value

I have this query that is giving me an error The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. Query: select COUNT(*) from dbo.patient ...
user avatar
  • 25
57 votes
5 answers
63k views

How to combine date and time to datetime2 in SQL Server?

Given the following components DECLARE @D DATE = '2013-10-13' DECLARE @T TIME(7) = '23:59:59.9999999' What is the best way of combining them to produce a DATETIME2(7) result with value '2013-10-13 ...
user avatar