Questions tagged [datetime2]
A SQL Server type that defines a date that is combined with a time of day that is based on 24-hour clock. datetime2 can be considered as an extension of the existing datetime type that has a larger date range, a larger default fractional precision, and optional user-specified precision.
135
questions
1
vote
1answer
33 views
Why can datetime allow this decimal format but datetime2 won't?
I just ran into an issue where my program was not able to convert a string to a datetime2 value. The value was 12/17.2020. When converting this to datetime it worked, but when converting it to ...
-1
votes
2answers
62 views
How to remove trailing zeros from milliseconds value(datetime 2)in string format by one query
I used SQL Server. I converted value from datetime2 column with different scales to string and compare them to process null values if they are exist. So, I need to convert this data without tailing ...
0
votes
0answers
49 views
Micro Focus COBOL 5 Won't Accept SQL Server Dates
A team of developers are trying to upgrade our COBOL from Micro Focus 4 to 5 - and our date processing keeps throwing exceptions
working storage
...
01 WS-CURRENT-TIMESTAMP PIC X(026).
...
...
0
votes
3answers
48 views
Add/Select mulitiple columns in SQL based on another column's value condition
I am using SQL Server. Here is the scenario:
Let say I have a tableA:
UserId UserName TransactionType TransactionDateTime
1 Staff1 NULL NULL
2 Staff2 1 ...
0
votes
0answers
82 views
DATETIME2 to UNIX timestamp
Is there a simple function to convert the the datetime2 format to output correctly using PHP?
I'm able to get a correct date, but the time always returns as 00:00:00, despite showing correctly on the ...
0
votes
1answer
67 views
How to convert nvarchar timestamp to datetime2 in SQL Server?
I've moved my data to a staging table and will eventually insert this data into my main table. I'm having issues converting nvarchar to datetime2. My nvarchar datetime columns have values that look ...
0
votes
0answers
29 views
AWS Data Migration Services - SQL Server to Redshift - Datetime2 to varchar
Currently doing a SQL Server v14.0.2027.2 to Redshift data migration using AWS DMS.
Experiencing a problem where nullable Datetime2 columns in SQL server are being added to Redshift as varchar. ...
1
vote
4answers
179 views
Why converting empty value to datetime2 is throwing conversion error in SQL?
In C# I get this value for a datetime2 type:
{01/01/0001 00:00:00}
Which is because the client is send empty value. In database it throws error:
The conversion of a datetime2 data type to a ...
0
votes
0answers
242 views
Operand type clash: datetime2 is incompatible with int, when using convert NVARCHAR
I can't save this view because of the error. I'm not using cast because I thought it wasn't necessary. I'm new to T-SQL and am very unclear on how to track down the source of hte error since SSMS ...
1
vote
1answer
149 views
SQL Server : order by time portion of Datetime2 timestamp
I have a table of orders with a datetime2(7) column O_CreatedOn and I would like to order this recordset by the time portion only of the O_CreatedOn column.
The reason for this is that I need to ...
1
vote
1answer
225 views
How to convert datetime2 column to bigint with the datediff in place
I have a column named 'order_confirmation_date' that is in Datetime2 format and I need it to work with bigint with the below query that uses datediff b/w the column value and getdate().
SELECT
...
0
votes
0answers
121 views
Code First, set GetDate() on DateTime2 field
I've followed the examples like accepted here: Possible to default DateTime field to GETDATE() with Entity Framework Migrations?
In Sql server, the "Default Binding or Value" is now getting set to ('...
0
votes
1answer
37 views
Is there a “Try” equivelent of DATETIME2FROMPARTS?
Given the following fields:
Y INT, --Year.
M INT, --Month.
D INT, --Day.
T FLOAT --Hours (H), minutes (m), seconds (s) and milliseconds (x) (in the form HHmmss.xxx).
Is there a way to attempt to ...
6
votes
1answer
400 views
SQL Server 2016 : join DATETIME2(3) with DATETIME
I'm getting unexpected results when joining on a DATETIME2(3) and a DATETIME column with PK, in SQL Server 2016.
I have the following table:
CREATE TABLE DATETIME_TEST
(
[DATETIME] DATETIME ...
1
vote
1answer
43 views
How does one handle Date/Time component Overflow for Conversion to DATETIME2?
Supposing you have the following atrocious data structure in your SQL Server database to hold Date Times.
Year (int)
Month (int)
Day (int)
Hour (int)
Minute (int)
Second and Millisecond (float)
And ...
0
votes
1answer
79 views
Entity Framework not working correctly with DateTime column when converted to compatibilty 130
The below code was working with SQL Server Compatibility Level 100. However updating to 130, starting making the code below fail. I believe it has to do with the datetime and precision. The item ...
0
votes
1answer
57 views
How does one create a Deterministic Function returning a DATETIME2?
I have a table which nonsensically has DateTime values stored in Year (INT), Month (INT), Day (INT) and Time (FLOAT) columns; unfortunately I'm not allowed to change this but have a requirement to ...
2
votes
0answers
286 views
mssql-jdbc datetime java type is converted to datetime2 in compatible SQLServer 2014 vs SQLServer2016
We are using SQLServer 2012-2016.
DATETIME data type is part of the key in many tables.
when we execute query with jdbcTemplate.query(query, queryParams, resultSetExtractor)
What is send to ...
0
votes
1answer
138 views
SQL Server Export fails on DateTime2 => PostgreSQL
I am trying to export number databases from MS SQL to PostgreSQL.
Unfortunately SQL Server Export tool fails to work with DateTime2 type columns.
Everytime I am getting:
Error 0xc020844b: Data ...
-1
votes
1answer
281 views
Datetime2 vs. String performance in SQL Server
What are the advantages of having a column of type datetime2 in SQL Server instead of a string? Obviously strings are much more flexible. Are there performance advantages while querying?
I'm ...
1
vote
1answer
154 views
SQL: Combine DATEDIFF from two columns and update the table with this time
I have recently started with SQL so I'm still learning, this is also my first question so sorry in advance.
I have a Table, Messages_History with three columns tmStartTime, tmEndTime and tmTotal, all ...
0
votes
0answers
50 views
What are the dangers of converting all datetime columns in a database to datetime2
We have a database with over 100 tables which has already been deployed to tens of production sites. Initially all datetime columns were of type datetime, but as the system evolved we started to use ...
0
votes
1answer
16 views
How can I have two date variables in datetime2 type in sql?
I want to insert these values into existing table.
insert Schedule
([Title], MeetingTime)
values
(N'First meeting', ('2018-10-9 18:30:00' and '2018-11-13 18:30:00' )),
(N'Second meeting', ...
0
votes
1answer
127 views
Migrating to SQL Server 2017 : same query returns no rows sometimes
I've just upgraded to SQL Server 2017 from SQL Server 2014 (only dev environment yet) and noticed a very strange behavior : the same query has two different impacts on both servers.
The query has ...
3
votes
1answer
938 views
Changing the Dapper mapping for .net DateTime to use DbType DateTime2 and reinstating it back again
Similar to the question How can I get Dapper to map .net DateTime to DateTime2; but I want to be able to set it back again afterwards.
The currently accepted answer to that question involves changing ...
1
vote
3answers
664 views
Convert varchar “dd/mm/yyyy hh:mm:ss” to datetime2
I have a column of dates in varchar(50) format written as "dd/mm/yyyy"
I need to convert it to datetime2 format however when it runs it assumes that the format is "mm/dd/yyyy" and converts accordingly,...
0
votes
1answer
16 views
Conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value during migration EF 6
When applying a migration using "update-database" I get an error about conversion of datetime2 to datetime. How do I fix this?
0
votes
3answers
571 views
SQL Server - How to remove trailing zeros from milliseconds in datetime2 data type
How can I use any cast or convert function to remove trailing zeros from milliseconds in datetime2 data type.
For example, I have these data:
2018-02-17 13:26:55.033000
2018-02-17 12:37:12.300000
...
0
votes
2answers
240 views
Weird datetime and dateime2 millisecond comparison issue
I have been facing typical comparison issue with datetime and datime2. I am unable to understand why in 1 & 2 doesn't return equal result. I have read about how datetime value stored from msdn and ...
1
vote
0answers
397 views
Java Date to SQL Server datetime2 via Hibernate: getting ms rounded like datetime?
My Java fields are defined as Dates, and like some others I have run into the issue of SQL Server's datetime rounding milliseconds strangely (to the nearest 1/300 sec). Accordingly, I changed my ...
0
votes
0answers
378 views
Default Value for datetime2 field in EF6 does not works [duplicate]
I am using EF6 code first approach, wherein i have class with CreatedDate field, i have decorated it with [DefaultValue("getutcdate()")] and the Default binding has also been generated by EF, however, ...
0
votes
0answers
48 views
PayPal IPN SqlDateTime overflow
I am have been struggling to insert paypal IPN Data into my database. I keep getting the exception:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
Here is ...
2
votes
2answers
173 views
How to compare dates with different precision
I asked this question regarding how to compare datetime2 values, but ignoring the nanoseconds. Since there is some rounding involved, it fails to compare the values properly.
In java, I can get a ...
0
votes
1answer
2k views
How can I get the full milliseconds in SQL server?
DECLARE @Now DATETIME2(7) = SYSDATETIME();
SELECT
[Datetime2(1)] = DATEPART(MILLISECOND,CAST(@Now AS DATETIME2(1))),
[Datetime2(2)] = DATEPART(MILLISECOND,CAST(@Now AS DATETIME2(2))),
[...
4
votes
4answers
415 views
SQL ignore nanoseconds when comparing datetime2
I have 2 tables with a datetime2 field each. One of the tables has stored nanoseconds as well, while the other one only stores up to milliseconds (there is no way to change this data). Now I want to ...
0
votes
0answers
2k views
Convert datetime to binary data type SQL Server
I have a value
20 01 01 29 13 11 58 15 46 52 00 00 00
which got migrated to a SQL Server table of column type binary as 0x20010129131158154652000000. If we observe it is exact value just prefixed ...
-3
votes
2answers
7k views
Default Value for datetime2
What is the default value for datetime2?
Edited: Sorry maybe I explain me wrong, I've tried to insert getDate() and it save me this value.
I need to know what is the value in this field (red one) of ...
0
votes
0answers
61 views
Importing DateTime data to DateTimeOffset
Lets say I have a table called Test.
Test has a Column called CreatedDate. This is the DateTimeOffset at the time of creation of the row.
Test also has a Column called ExternalDate. This is an ...
2
votes
5answers
6k views
Concatenate date and string to create datetime in SQL
I need to concatenate a datetime and a time field in SQL to a single date time.
e.g I have a datetime of 2017-09-05 00:00:00.000 and a string time of 11:00. What I want is a single field in a view of ...
0
votes
1answer
1k views
How to convert '01/01/0001' to datetime2
I was trying to display a '01/01/0001' from sql if the value is null. But when I convert the value into datetime2, it says:
Msg 517, Level 16, State 3, Line 18
Adding a value to a 'datetime2' ...
2
votes
0answers
476 views
Entity Framework Migration to datetime2
We use Entity Framework 6 code first. We recently decided to move datetime format in the database to datetime2 format. Our database currently contains lot of data and about 262 tables.
By googling it, ...
5
votes
2answers
9k views
SQL Server smalldatetime vs datetime2
I've read several articles about using data types that support dates in SQL Server but I'm still undecided about what kind of data to use.
All the people says to use the new and powerful datetime2 ...
0
votes
2answers
203 views
Converting a custom date string into SQL datetime2
I have to load a CSV file into a temp table in SQL server 2008. There is a column in the CSV file which contains a date string formatted like this 11/04/2017 at 08:24:52. How can I parse this string ...
3
votes
2answers
843 views
ssis script converts System.DateTime to DT_DBTIMESTAMP but does not convert to DT_DBTIMESTAMP2
when i try to pass DateTime.Now value to DT_DBTIMESTAMP field via this code
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
Output0Buffer.AddRow();
Output0Buffer.Dt = DateTime....
1
vote
1answer
520 views
Passing in variables to SQL Server stored procedure, where clause
I am writing an application responsible for archiving data and we have the configuration in a database table
Id | TableName | ColumnName | RetentionAmountInDays
1 | ...
1
vote
1answer
2k views
SQL TRY_CONVERT DateTime vs DateTime2
I have a situation where I need to convert datetime string values in a column to a more standardised format, the converting process is quiet manual I am not just casting and storing.
So the script ...
0
votes
0answers
60 views
SQL: datetime2 overflow in WHERE, but not in SELECT
I've seen plenty of threads about datetime2 overflows when hitting the minimum date, but I don't have that in my data. Additionally, the DATEADD works fine in the SELECT statement, but not in the ...
-1
votes
2answers
189 views
Is it possible to configure application for replace DateTime.MinValue to null?
I work on a big ASP.NET MVC application. This app contains many forms with date time controls. Values of this controls is optional. Also in database field where store values from this controls can be ...
0
votes
1answer
744 views
How do I Check for valid date in C# (that has a datetime type not datetime2)?
I've been searching but haven't found my answer so forgive me if this question is a duplicate.
I've got a .Net C# application that is using entity framework (EF) to communicate with a SQL Server ...
2
votes
1answer
286 views
Loss of precision when mapping datatable columns to datetime2 fields
Background
The field TimestampCreation is created as such in the DB:
[TimestampCreation] [datetime2](7) NOT NULL
If I add the field to a datatable like this:
table.Columns.Add(new DataColumn("...